Skip to content

Commit 3995296

Browse files
authored
[Feature] [Platform] Chart Integration (#1766)
1 parent f89e64d commit 3995296

32 files changed

+2339
-241
lines changed

.golangci.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ linters-settings:
4545
pkg: github.com/arangodb/kube-arangodb/integrations/scheduler/v1
4646
- alias: pbSchedulerV1
4747
pkg: github.com/arangodb/kube-arangodb/integrations/scheduler/v1/definition
48+
- alias: pbImplSchedulerV2
49+
pkg: github.com/arangodb/kube-arangodb/integrations/scheduler/v2
50+
- alias: pbSchedulerV2
51+
pkg: github.com/arangodb/kube-arangodb/integrations/scheduler/v2/definition
4852
- alias: pbImplSharedV1
4953
pkg: github.com/arangodb/kube-arangodb/integrations/shared/v1
5054
- alias: pbSharedV1

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- (Maintenance) Extract GRPC Client Package
2323
- (Feature) (Platform) Chart
2424
- (Feature) (Scheduler) Deployment Scale Functionality
25+
- (Feature) (Platform) Chart Integration
2526

2627
## [1.2.43](https://github.com/arangodb/kube-arangodb/tree/1.2.43) (2024-10-14)
2728
- (Feature) ArangoRoute CRD

integrations/scheduler/v2/chart.go

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2024 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package v2
22+
23+
import (
24+
"context"
25+
26+
"google.golang.org/grpc/codes"
27+
"google.golang.org/grpc/status"
28+
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
30+
pbSchedulerV2 "github.com/arangodb/kube-arangodb/integrations/scheduler/v2/definition"
31+
platformApi "github.com/arangodb/kube-arangodb/pkg/apis/platform/v1alpha1"
32+
"github.com/arangodb/kube-arangodb/pkg/util"
33+
)
34+
35+
func (i *implementation) ListCharts(req *pbSchedulerV2.SchedulerV2ListChartsRequest, server pbSchedulerV2.SchedulerV2_ListChartsServer) error {
36+
ctx := server.Context()
37+
38+
var ct string
39+
40+
for {
41+
resp, err := i.client.Client().Arango().PlatformV1alpha1().ArangoPlatformCharts(i.client.Namespace()).List(ctx, meta.ListOptions{
42+
Limit: util.OptionalType(req.Items, 128),
43+
Continue: ct,
44+
})
45+
if err != nil {
46+
logger.Err(err).Warn("Unable to run action: ListCharts")
47+
return asGRPCError(err)
48+
}
49+
50+
var res pbSchedulerV2.SchedulerV2ListChartsResponse
51+
52+
for _, item := range resp.Items {
53+
res.Charts = append(res.Charts, item.GetName())
54+
}
55+
56+
if err := server.Send(&res); err != nil {
57+
logger.Err(err).Warn("Unable to send action response: ListCharts")
58+
return err
59+
}
60+
61+
if resp.Continue == "" {
62+
return nil
63+
}
64+
65+
ct = resp.Continue
66+
}
67+
}
68+
69+
func (i *implementation) GetChart(ctx context.Context, in *pbSchedulerV2.SchedulerV2GetChartRequest) (*pbSchedulerV2.SchedulerV2GetChartResponse, error) {
70+
resp, err := i.client.Client().Arango().PlatformV1alpha1().ArangoPlatformCharts(i.client.Namespace()).Get(ctx, in.GetName(), meta.GetOptions{})
71+
if err != nil {
72+
logger.Err(err).Warn("Unable to run action: GetChart")
73+
return nil, asGRPCError(err)
74+
}
75+
76+
if !resp.Status.Conditions.IsTrue(platformApi.SpecValidCondition) {
77+
return nil, status.Errorf(codes.Unavailable, "Chart Spec is invalid")
78+
}
79+
80+
if info := resp.Status.Info; info == nil {
81+
return nil, status.Errorf(codes.Unavailable, "Chart Infos are missing")
82+
} else {
83+
if !info.Valid {
84+
if msg := info.Message; msg == "" {
85+
return nil, status.Errorf(codes.Unavailable, "Chart is not Valid")
86+
} else {
87+
return nil, status.Errorf(codes.Unavailable, "Chart is not Valid: %s", msg)
88+
}
89+
} else {
90+
if details := info.Details; details == nil {
91+
return nil, status.Errorf(codes.Unavailable, "Chart Details are missing")
92+
} else {
93+
return &pbSchedulerV2.SchedulerV2GetChartResponse{
94+
Chart: info.Definition,
95+
Info: chartInfoDetailsAsInfo(details),
96+
}, nil
97+
}
98+
}
99+
}
100+
}
101+
102+
func chartInfoDetailsAsInfo(in *platformApi.ChartDetails) *pbSchedulerV2.SchedulerV2ChartInfo {
103+
if in == nil {
104+
return nil
105+
}
106+
107+
return &pbSchedulerV2.SchedulerV2ChartInfo{
108+
Name: in.Name,
109+
Version: in.Version,
110+
}
111+
}

0 commit comments

Comments
 (0)