Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] [Platform] Platform Requirements support #1772

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- (Feature) (Platform) Chart Integration
- (Maintenance) Switch to google.golang.org/protobuf
- (Feature) Add DebugPackage to the OPS Binary
- (Feature) (Platform) Platform Requirements support

## [1.2.43](https://github.com/arangodb/kube-arangodb/tree/1.2.43) (2024-10-14)
- (Feature) ArangoRoute CRD
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ require (
)

require (
github.com/Masterminds/semver/v3 v3.3.0
github.com/aws/aws-sdk-go v1.55.5
helm.sh/helm/v3 v3.16.2
)
Expand All @@ -85,7 +86,6 @@ require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/MakeNowJust/heredoc v1.0.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.3.0 // indirect
github.com/Masterminds/sprig/v3 v3.3.0 // indirect
github.com/Masterminds/squirrel v1.5.4 // indirect
github.com/Microsoft/hcsshim v0.11.4 // indirect
Expand Down
202 changes: 147 additions & 55 deletions integrations/scheduler/v2/definition/chart.pb.go

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions integrations/scheduler/v2/definition/chart.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ message SchedulerV2ChartInfo {
string name = 1;
// Chart Version
string version = 2;
// Keeps the Platform details from the output
optional SchedulerV2ChartPlatform platform = 3;
}

// Chart Platform Details
message SchedulerV2ChartPlatform {
// List of the requirements
map<string, string> requirements = 1;
}

// SchedulerV2 ListCharts Request
Expand Down
73 changes: 67 additions & 6 deletions integrations/scheduler/v2/implementation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ package v2
import (
"context"
"testing"
"time"

"github.com/stretchr/testify/require"
"helm.sh/helm/v3/pkg/action"
core "k8s.io/api/core/v1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"

pbSchedulerV2 "github.com/arangodb/kube-arangodb/integrations/scheduler/v2/definition"
pbSharedV1 "github.com/arangodb/kube-arangodb/integrations/shared/v1/definition"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/helm"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/kerrors"
"github.com/arangodb/kube-arangodb/pkg/util/tests"
"github.com/arangodb/kube-arangodb/pkg/util/tests/suite"
)

func cleanup(t *testing.T, c helm.Client) func() {
Expand All @@ -47,6 +52,32 @@ func cleanup(t *testing.T, c helm.Client) func() {
require.NoError(t, err)
})
}

t.Run("Remove NS", func(t *testing.T) {
if err := c.Client().Kubernetes().CoreV1().Namespaces().Delete(context.Background(), tests.FakeNamespace, meta.DeleteOptions{}); !kerrors.IsNotFound(err) {
require.NoError(t, err)
}

for {
time.Sleep(time.Second)

if _, err := c.Client().Kubernetes().CoreV1().Namespaces().Get(context.Background(), tests.FakeNamespace, meta.GetOptions{}); !kerrors.IsNotFound(err) {
require.NoError(t, err)
continue
}

break
}
})

t.Run("Create NS", func(t *testing.T) {
_, err = c.Client().Kubernetes().CoreV1().Namespaces().Create(context.Background(), &core.Namespace{
ObjectMeta: meta.ObjectMeta{
Name: tests.FakeNamespace,
},
}, meta.CreateOptions{})
require.NoError(t, err)
})
})

return func() {
Expand All @@ -63,6 +94,23 @@ func cleanup(t *testing.T, c helm.Client) func() {
require.NoError(t, err)
})
}

t.Run("Remove NS", func(t *testing.T) {
if err := c.Client().Kubernetes().CoreV1().Namespaces().Delete(context.Background(), tests.FakeNamespace, meta.DeleteOptions{}); !kerrors.IsNotFound(err) {
require.NoError(t, err)
}

for {
time.Sleep(time.Second)

if _, err := c.Client().Kubernetes().CoreV1().Namespaces().Get(context.Background(), tests.FakeNamespace, meta.GetOptions{}); !kerrors.IsNotFound(err) {
require.NoError(t, err)
continue
}

break
}
})
})
}
}
Expand Down Expand Up @@ -139,7 +187,7 @@ func Test_Implementation(t *testing.T) {
status, err := scheduler.Install(context.Background(), &pbSchedulerV2.SchedulerV2InstallRequest{
Name: "test",
Values: nil,
Chart: example_1_0_0,
Chart: suite.GetChart(t, "example", "1.0.0"),
})
require.NoError(t, err)

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

t.Run("Install Outside", func(t *testing.T) {
resp, err := h.Install(context.Background(), example_1_0_0, nil, func(in *action.Install) {
resp, err := h.Install(context.Background(), suite.GetChart(t, "example", "1.0.0"), nil, func(in *action.Install) {
in.ReleaseName = "test-outside"
})
require.NoError(t, err)
Expand All @@ -173,7 +221,7 @@ func Test_Implementation(t *testing.T) {
status, err := scheduler.Install(context.Background(), &pbSchedulerV2.SchedulerV2InstallRequest{
Name: "test-x",
Values: nil,
Chart: example_1_0_0,
Chart: suite.GetChart(t, "example", "1.0.0"),
Options: &pbSchedulerV2.SchedulerV2InstallRequestOptions{
Labels: map[string]string{
"X": "X",
Expand All @@ -186,7 +234,7 @@ func Test_Implementation(t *testing.T) {
})

t.Run("Install Second Outside", func(t *testing.T) {
resp, err := h.Install(context.Background(), example_1_0_0, nil, func(in *action.Install) {
resp, err := h.Install(context.Background(), suite.GetChart(t, "example", "1.0.0"), nil, func(in *action.Install) {
in.ReleaseName = "test-outside-x"
in.Labels = map[string]string{
"X": "X",
Expand Down Expand Up @@ -234,7 +282,20 @@ func Test_Implementation(t *testing.T) {
status, err := scheduler.Upgrade(context.Background(), &pbSchedulerV2.SchedulerV2UpgradeRequest{
Name: "test",
Values: values,
Chart: example_1_0_0,
Chart: suite.GetChart(t, "example", "1.0.0"),
})
require.NoError(t, err)

require.NotNil(t, status.GetAfter())
t.Logf("Data: %s", string(status.GetAfter().GetValues()))
require.Len(t, status.GetAfter().GetValues(), len(values))
})

t.Run("Upgrade to 1", func(t *testing.T) {
status, err := scheduler.Upgrade(context.Background(), &pbSchedulerV2.SchedulerV2UpgradeRequest{
Name: "test",
Values: values,
Chart: suite.GetChart(t, "example", "1.0.1"),
})
require.NoError(t, err)

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

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

require.EqualValues(t, 2, status.GetRelease().GetVersion())
require.EqualValues(t, 3, status.GetRelease().GetVersion())
t.Logf("Data: %s", string(status.GetRelease().GetValues()))
require.Len(t, status.GetRelease().GetValues(), len(values))
})
Expand Down
Binary file removed integrations/scheduler/v2/suite/example-1.0.0.tgz
Binary file not shown.
3 changes: 0 additions & 3 deletions integrations/scheduler/v2/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ func init() {
})
}

//go:embed suite/example-1.0.0.tgz
var example_1_0_0 []byte

func Handler(t *testing.T, ctx context.Context, client helm.Client, mods ...Mod) svc.Handler {
handler, err := New(client, NewConfiguration().With(mods...))
require.NoError(t, err)
Expand Down
13 changes: 11 additions & 2 deletions pkg/apis/platform/v1alpha1/chart_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,17 @@
package v1alpha1

type ChartDetails struct {
Name string `json:"name,omitempty"`
Version string `json:"version,omitempty"`
Name string `json:"name,omitempty"`
Version string `json:"version,omitempty"`
Platform *ChartDetailsPlatform `json:"platform,omitempty"`
}

func (c *ChartDetails) GetPlatform() *ChartDetailsPlatform {
if c == nil {
return nil
}

return c.Platform
}

func (c *ChartDetails) GetName() string {
Expand Down
33 changes: 33 additions & 0 deletions pkg/apis/platform/v1alpha1/chart_details_platform.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// 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 v1alpha1

type ChartDetailsPlatform struct {
Requirements ChartDetailsPlatformRequirements `json:"requirements,omitempty"`
}

func (c *ChartDetailsPlatform) GetRequirements() ChartDetailsPlatformRequirements {
if c == nil {
return nil
}

return c.Requirements
}
37 changes: 37 additions & 0 deletions pkg/apis/platform/v1alpha1/chart_details_platform_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// 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 v1alpha1

import (
"github.com/arangodb/kube-arangodb/pkg/util"
)

type ChartDetailsPlatformRequirements map[string]ChartDetailsPlatformVersionConstrain

type ChartDetailsPlatformVersionConstrain string

func (c *ChartDetailsPlatformVersionConstrain) AsSemverConstrain() (util.VersionConstrain, error) {
if c == nil {
return nil, nil
}

return util.NewVersionConstrain(string(*c))
}
52 changes: 51 additions & 1 deletion pkg/apis/platform/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions pkg/apis/shared/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ func ValidateList[T any](in []T, validator func(T) error, checks ...func(in []T)
return WithErrors(errors...)
}

// ValidateInterfaceMap Validates object if is not nil with path
func ValidateInterfaceMap[T ValidateInterface](in map[string]T) error {
errors := make([]error, 0, len(in))

for id := range in {
if err := PrefixResourceError(id, in[id].Validate()); err != nil {
errors = append(errors, err)
}
}

return WithErrors(errors...)
}

// ValidateMap validates all elements on the list
func ValidateMap[T any](in map[string]T, validator func(string, T) error, checks ...func(in map[string]T) error) error {
errors := make([]error, 0, len(in)+len(checks))
Expand Down
Loading