Skip to content

Commit

Permalink
[Feature] [Platform] Chart Integration (#1766)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajanikow authored Nov 15, 2024
1 parent f89e64d commit 3995296
Show file tree
Hide file tree
Showing 32 changed files with 2,339 additions and 241 deletions.
4 changes: 4 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ linters-settings:
pkg: github.com/arangodb/kube-arangodb/integrations/scheduler/v1
- alias: pbSchedulerV1
pkg: github.com/arangodb/kube-arangodb/integrations/scheduler/v1/definition
- alias: pbImplSchedulerV2
pkg: github.com/arangodb/kube-arangodb/integrations/scheduler/v2
- alias: pbSchedulerV2
pkg: github.com/arangodb/kube-arangodb/integrations/scheduler/v2/definition
- alias: pbImplSharedV1
pkg: github.com/arangodb/kube-arangodb/integrations/shared/v1
- alias: pbSharedV1
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- (Maintenance) Extract GRPC Client Package
- (Feature) (Platform) Chart
- (Feature) (Scheduler) Deployment Scale Functionality
- (Feature) (Platform) Chart Integration

## [1.2.43](https://github.com/arangodb/kube-arangodb/tree/1.2.43) (2024-10-14)
- (Feature) ArangoRoute CRD
Expand Down
111 changes: 111 additions & 0 deletions integrations/scheduler/v2/chart.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
//
// DISCLAIMER
//
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package v2

import (
"context"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"

pbSchedulerV2 "github.com/arangodb/kube-arangodb/integrations/scheduler/v2/definition"
platformApi "github.com/arangodb/kube-arangodb/pkg/apis/platform/v1alpha1"
"github.com/arangodb/kube-arangodb/pkg/util"
)

func (i *implementation) ListCharts(req *pbSchedulerV2.SchedulerV2ListChartsRequest, server pbSchedulerV2.SchedulerV2_ListChartsServer) error {
ctx := server.Context()

var ct string

for {
resp, err := i.client.Client().Arango().PlatformV1alpha1().ArangoPlatformCharts(i.client.Namespace()).List(ctx, meta.ListOptions{
Limit: util.OptionalType(req.Items, 128),
Continue: ct,
})
if err != nil {
logger.Err(err).Warn("Unable to run action: ListCharts")
return asGRPCError(err)
}

var res pbSchedulerV2.SchedulerV2ListChartsResponse

for _, item := range resp.Items {
res.Charts = append(res.Charts, item.GetName())
}

if err := server.Send(&res); err != nil {
logger.Err(err).Warn("Unable to send action response: ListCharts")
return err
}

if resp.Continue == "" {
return nil
}

ct = resp.Continue
}
}

func (i *implementation) GetChart(ctx context.Context, in *pbSchedulerV2.SchedulerV2GetChartRequest) (*pbSchedulerV2.SchedulerV2GetChartResponse, error) {
resp, err := i.client.Client().Arango().PlatformV1alpha1().ArangoPlatformCharts(i.client.Namespace()).Get(ctx, in.GetName(), meta.GetOptions{})
if err != nil {
logger.Err(err).Warn("Unable to run action: GetChart")
return nil, asGRPCError(err)
}

if !resp.Status.Conditions.IsTrue(platformApi.SpecValidCondition) {
return nil, status.Errorf(codes.Unavailable, "Chart Spec is invalid")
}

if info := resp.Status.Info; info == nil {
return nil, status.Errorf(codes.Unavailable, "Chart Infos are missing")
} else {
if !info.Valid {
if msg := info.Message; msg == "" {
return nil, status.Errorf(codes.Unavailable, "Chart is not Valid")
} else {
return nil, status.Errorf(codes.Unavailable, "Chart is not Valid: %s", msg)
}
} else {
if details := info.Details; details == nil {
return nil, status.Errorf(codes.Unavailable, "Chart Details are missing")
} else {
return &pbSchedulerV2.SchedulerV2GetChartResponse{
Chart: info.Definition,
Info: chartInfoDetailsAsInfo(details),
}, nil
}
}
}
}

func chartInfoDetailsAsInfo(in *platformApi.ChartDetails) *pbSchedulerV2.SchedulerV2ChartInfo {
if in == nil {
return nil
}

return &pbSchedulerV2.SchedulerV2ChartInfo{
Name: in.Name,
Version: in.Version,
}
}
Loading

0 comments on commit 3995296

Please sign in to comment.