8000 [Feature] [Platform] Platform Requirements support · arangodb/kube-arangodb@9d61f8d · GitHub
[go: up one dir, main page]

Skip to content

Commit 9d61f8d

Browse files
committed
[Feature] [Platform] Platform Requirements support
1 parent 44f2bf6 commit 9d61f8d

32 files changed

+887
-107
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
- (Feature) (Platform) Chart Integration
2626
- (Maintenance) Switch to google.golang.org/protobuf
2727
- (Feature) Add DebugPackage to the OPS Binary
28+
- (Feature) (Platform) Platform Requirements support
2829

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

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ require (
7373
)
7474

7575
require (
76+
github.com/Masterminds/semver/v3 v3.3.0
7677
github.com/aws/aws-sdk-go v1.55.5
7778
helm.sh/helm/v3 v3.16.2
7879
)
@@ -85,7 +86,6 @@ require (
8586
github.com/BurntSushi/toml v1.3.2 // indirect
8687
github.com/MakeNowJust/heredoc v1.0.0 // indirect
8788
github.com/Masterminds/goutils v1.1.1 // indirect
88-
github.com/Masterminds/semver/v3 v3.3.0 // indirect
8989
github.com/Masterminds/sprig/v3 v3.3.0 // indirect
9090
github.com/Masterminds/squirrel v1.5.4 // indirect
9191
github.com/Microsoft/hcsshim v0.11.4 // indirect

integrations/scheduler/v2/definition/chart.pb.go

Lines changed: 147 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integrations/scheduler/v2/definition/chart.proto

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ message SchedulerV2ChartInfo {
3030
string name = 1;
3131
// Chart Version
3232
string version = 2;
33+
// Keeps the Platform details from the output
34+
optional SchedulerV2ChartPlatform platform = 3;
35+
}
36+
37+
// Chart Platform Details
38+
message SchedulerV2ChartPlatform {
39+
// List of the requirements
40+
map<string, string> requirements = 1;
3341
}
3442

3543
// SchedulerV2 ListCharts Request

integrations/scheduler/v2/implementation_test.go

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,19 @@ package v2
2323
import (
2424
"context"
2525
"testing"
26+
"time"
2627

2728
"github.com/stretchr/testify/require"
2829
"helm.sh/helm/v3/pkg/action"
30+
core "k8s.io/api/core/v1"
31+
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
2932

3033
pbSchedulerV2 "github.com/arangodb/kube-arangodb/integrations/scheduler/v2/definition"
3134
pbSharedV1 "github.com/arangodb/kube-arangodb/integrations/shared/v1/definition"
3235
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/helm"
36+
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors"
3337
"github.com/arangodb/kube-arangodb/pkg/util/tests"
38+
"github.com/arangodb/kube-arangodb/pkg/util/tests/suite"
3439
)
3540

3641
func cleanup(t *testing.T, c helm.Client) func() {
@@ -47,6 +52,32 @@ func cleanup(t *testing.T, c helm.Client) func() {
4752
require.NoError(t, err)
4853
})
4954
}
55+
56+
t.Run("Remove NS", func(t *testing.T) {
57+
if err := c.Client().Kubernetes().CoreV1().Namespaces().Delete(context.Background(), tests.FakeNamespace, meta.DeleteOptions{}); !kerrors.IsNotFound(err) {
58+
require.NoError(t, err)
59+
}
60+
61+
for {
62+
time.Sleep(time.Second)
63+
64 10000 +
if _, err := c.Client().Kubernetes().CoreV1().Namespaces().Get(context.Background(), tests.FakeNamespace, meta.GetOptions{}); !kerrors.IsNotFound(err) {
65+
require.NoError(t, err)
66+
continue
67+
}
68+
69+
break
70+
}
71+
})
72+
73+
t.Run("Create NS", func(t *testing.T) {
74+
_, err = c.Client().Kubernetes().CoreV1().Namespaces().Create(context.Background(), &core.Namespace{
75+
ObjectMeta: meta.ObjectMeta{
76+
Name: tests.FakeNamespace,
77+
},
78+
}, meta.CreateOptions{})
79+
require.NoError(t, err)
80+
})
5081
})
5182

5283
return func() {
@@ -63,6 +94,23 @@ func cleanup(t *testing.T, c helm.Client) func() {
6394
require.NoError(t, err)
6495
})
6596
}
97+
98+
t.Run("Remove NS", func(t *testing.T) {
99+
if err := c.Client().Kubernetes().CoreV1().Namespaces().Delete(context.Background(), tests.FakeNamespace, meta.DeleteOptions{}); !kerrors.IsNotFound(err) {
100+
require.NoError(t, err)
101+
}
102+
103+
for {
104+
time.Sleep(time.Second)
105+
106+
if _, err := c.Client().Kubernetes().CoreV1().Namespaces().Get(context.Background(), tests.FakeNamespace, meta.GetOptions{}); !kerrors.IsNotFound(err) {
107+
require.NoError(t, err)
108+
continue
109+
}
110+
111+
break
112+
}
113+
})
66114
})
67115
}
68116
}
@@ -139,7 +187,7 @@ func Test_Implementation(t *testing.T) {
139187
status, err := scheduler.Install(context.Background(), &pbSchedulerV2.SchedulerV2InstallRequest{
140188
Name: "test",
141189
Values: nil,
142-
Chart: example_1_0_0,
190+
Chart: suite.GetChart(t, "example", "1.0.0"),
143191
})
144192
require.NoError(t, err)
145193

@@ -154,7 +202,7 @@ func Test_Implementation(t *testing.T) {
154202
})
155203

156204
t.Run("Install Outside", func(t *testing.T) {
157-
resp, err := h.Install(context.Background(), example_1_0_0, nil, func(in *action.Install) {
205+
resp, err := h.Install(context.Background(), suite.GetChart(t, "example", "1.0.0"), nil, func(in *action.Install) {
158206
in.ReleaseName = "test-outside"
159207
})
160208
require.NoError(t, err)
@@ -173,7 +221,7 @@ func Test_Implementation(t *testing.T) {
173221
status, err := scheduler.Install(context.Background(), &pbSchedulerV2.SchedulerV2InstallRequest{
174222
Name: "test-x",
175223
Values: nil,
176-
Chart: example_1_0_0,
224+
Chart: suite.GetChart(t, "example", "1.0.0"),
177225
Options: &pbSchedulerV2.SchedulerV2InstallRequestOptions{
178226
Labels: map[string]string{
179227
"X": "X",
@@ -186,7 +234,7 @@ func Test_Implementation(t *testing.T) {
186234
})
187235

188236
t.Run("Install Second Outside", func(t *testing.T) {
189-
resp, err := h.Install(context.Background(), example_1_0_0, nil, func(in *action.Install) {
237+
resp, err := h.Install(context.Background(), suite.GetChart(t, "example", "1.0.0"), nil, func(in *action.Install) {
190238
in.ReleaseName = "test-outside-x"
191239
in.Labels = map[string]string{
192240
"X": "X",
@@ -234,7 +282,20 @@ func Test_Implementation(t *testing.T) {
234282
status, err := scheduler.Upgrade(context.Background(), &pbSchedulerV2.SchedulerV2UpgradeRequest{
235283
Name: "test",
236284
Values: values,
237-
Chart: example_1_0_0,
285+
Chart: suite.GetChart(t, "example", "1.0.0"),
286+
})
287+
require.NoError(t, err)
288+
289+
require.NotNil(t, status.GetAfter())
290+
t.Logf("Data: %s", string(status.GetAfter().GetValues()))
291+
require.Len(t, status.GetAfter().GetValues(), len(values))
292+
})
293+
294+
t.Run("Upgrade to 1", func(t *testing.T) {
295+
status, err := scheduler.Upgrade(context.Background(), &pbSchedulerV2.SchedulerV2UpgradeRequest{
296+
Name: "test",
297+
Values: values,
298+
Chart: suite.GetChart(t, "example", "1.0.1"),
238299
})
239300
require.NoError(t, err)
240301

@@ -251,7 +312,7 @@ func Test_Implementation(t *testing.T) {
251312

252313
require.NotNil(t, status.GetRelease())
253314

254-
require.EqualValues(t, 2, status.GetRelease().GetVersion())
315+
require.EqualValues(t, 3, status.GetRelease().GetVersion())
255316
t.Logf("Data: %s", string(status.GetRelease().GetValues()))
256317
require.Len(t, status.GetRelease().GetValues(), len(values))
257318
})
-588 Bytes
Binary file not shown.

integrations/scheduler/v2/suite_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ func init() {
4444
})
4545
}
4646

47-
//go:embed suite/example-1.0.0.tgz
48-
var example_1_0_0 []byte
49-
5047
func Handler(t *testing.T, ctx context.Context, client helm.Client, mods ...Mod) svc.Handler {
5148
handler, err := New(client, NewConfiguration().With(mods...))
5249
require.NoError(t, err)

pkg/apis/platform/v1alpha1/chart_details.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,17 @@
2121
package v1alpha1
2222

2323
type ChartDetails struct {
24-
Name string `json:"name,omitempty"`
25-
Version string `json:"version,omitempty"`
24+
Name string `json:"name,omitempty"`
25+
Version string `json:"version,omitempty"`
26+
Platform *ChartDetailsPlatform `json:"platform,omitempty"`
27+
}
28+
29+
func (c *ChartDetails) GetPlatform() *ChartDetailsPlatform {
30+
if c == nil {
31+
return nil
32+
}
33+
34+
return c.Platform
2635
}
2736

2837
func (c *ChartDetails) GetName() string {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 v1alpha1
22+
23+
type ChartDetailsPlatform struct {
24+
Requirements ChartDetailsPlatformRequirements `json:"requirements,omitempty"`
25+
}
26+
27+
func (c *ChartDetailsPlatform) GetRequirements() ChartDetailsPlatformRequirements {
28+
if c == nil {
29+
return nil
30+
}
31+
32+
return c.Requirements
33+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 v1alpha1
22+
23+
import (
24+
"github.com/arangodb/kube-arangodb/pkg/util"
25+
)
26+
27+
type ChartDetailsPlatformRequirements map[string]ChartDetailsPlatformVersionConstrain
28+
29+
type ChartDetailsPlatformVersionConstrain string
30+
31+
func (c *ChartDetailsPlatformVersionConstrain) AsSemverConstrain() (util.VersionConstrain, error) {
32+
if c == nil {
33+
return nil, nil
34+
}
35+
36+
return util.NewVersionConstrain(string(*c))
37+
}

pkg/apis/platform/v1alpha1/zz_generated.deepcopy.go

Lines changed: 51 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/shared/validate.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,19 @@ func ValidateList[T any](in []T, validator func(T) error, checks ...func(in []T)
207207
return WithErrors(errors...)
208208
}
209209

210+
// ValidateInterfaceMap Validates object if is not nil with path
211+
func ValidateInterfaceMap[T ValidateInterface](in map[string]T) error {
212+
errors := make([]error, 0, len(in))
213+
214+
for id := range in {
215+
if err := PrefixResourceError(id, in[id].Validate()); err != nil {
216+
errors = append(errors, err)
217+
}
218+
}
219+
220+
return WithErrors(errors...)
221+
}
222+
210223
// ValidateMap validates all elements on the list
211224
func ValidateMap[T any](in map[string]T, validator func(string, T) error, checks ...func(in map[string]T) error) error {
212225
errors := make([]error, 0, len(in)+len(checks))

0 commit comments

Comments
 (0)
0