-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] ArangoProfile Selectors (#1627)
- Loading branch information
Showing
23 changed files
with
808 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// | ||
// 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 resources | ||
|
||
import ( | ||
core "k8s.io/api/core/v1" | ||
|
||
"github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/interfaces" | ||
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared" | ||
) | ||
|
||
type ImagePullSecrets []string | ||
|
||
var _ interfaces.Pod[Image] = &Image{} | ||
|
||
type Image struct { | ||
// ImagePullSecrets define Secrets used to pull Image from registry | ||
ImagePullSecrets ImagePullSecrets `json:"imagePullSecrets,omitempty"` | ||
} | ||
|
||
func (i *Image) Apply(pod *core.PodTemplateSpec) error { | ||
if i == nil { | ||
return nil | ||
} | ||
|
||
for _, secret := range i.ImagePullSecrets { | ||
if hasImagePullSecret(pod.Spec.ImagePullSecrets, secret) { | ||
continue | ||
} | ||
|
||
pod.Spec.ImagePullSecrets = append(pod.Spec.ImagePullSecrets, core.LocalObjectReference{ | ||
Name: secret, | ||
}) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (i *Image) With(other *Image) *Image { | ||
if i == nil && other == nil { | ||
return nil | ||
} | ||
|
||
if other == nil { | ||
return i.DeepCopy() | ||
} | ||
|
||
return other.DeepCopy() | ||
} | ||
|
||
func (i *Image) Validate() error { | ||
if i == nil { | ||
return nil | ||
} | ||
|
||
return shared.WithErrors( | ||
shared.PrefixResourceErrors("pullSecrets", shared.ValidateList(i.ImagePullSecrets, shared.ValidateResourceName)), | ||
) | ||
} | ||
|
||
func hasImagePullSecret(secrets []core.LocalObjectReference, secret string) bool { | ||
for _, sec := range secrets { | ||
if sec.Name == secret { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// | ||
// 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 resources | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
core "k8s.io/api/core/v1" | ||
) | ||
|
||
func applyImage(t *testing.T, template *core.PodTemplateSpec, ns ...*Image) func(in func(t *testing.T, pod *core.PodTemplateSpec)) { | ||
var i *Image | ||
|
||
for _, n := range ns { | ||
require.NoError(t, n.Validate()) | ||
|
||
i = i.With(n) | ||
|
||
require.NoError(t, i.Validate()) | ||
} | ||
|
||
template = template.DeepCopy() | ||
|
||
if template == nil { | ||
template = &core.PodTemplateSpec{} | ||
} | ||
|
||
require.NoError(t, i.Apply(template)) | ||
|
||
return func(in func(t *testing.T, spec *core.PodTemplateSpec)) { | ||
t.Run("Validate", func(t *testing.T) { | ||
in(t, template) | ||
}) | ||
} | ||
} | ||
|
||
func Test_Image(t *testing.T) { | ||
t.Run("With Nil", func(t *testing.T) { | ||
applyImage(t, nil, nil)(func(t *testing.T, pod *core.PodTemplateSpec) { | ||
require.Len(t, pod.Spec.ImagePullSecrets, 0) | ||
}) | ||
}) | ||
t.Run("With Empty", func(t *testing.T) { | ||
applyImage(t, &core.PodTemplateSpec{})(func(t *testing.T, pod *core.PodTemplateSpec) { | ||
require.Len(t, pod.Spec.ImagePullSecrets, 0) | ||
}) | ||
}) | ||
t.Run("With PS", func(t *testing.T) { | ||
applyImage(t, &core.PodTemplateSpec{}, &Image{ | ||
ImagePullSecrets: []string{ | ||
"secret", | ||
}, | ||
})(func(t *testing.T, pod *core.PodTemplateSpec) { | ||
require.Len(t, pod.Spec.ImagePullSecrets, 1) | ||
require.Equal(t, "secret", pod.Spec.ImagePullSecrets[0].Name) | ||
}) | ||
}) | ||
t.Run("With PS2", func(t *testing.T) { | ||
applyImage(t, &core.PodTemplateSpec{}, &Image{ | ||
ImagePullSecrets: []string{ | ||
"secret", | ||
"secret", | ||
}, | ||
})(func(t *testing.T, pod *core.PodTemplateSpec) { | ||
require.Len(t, pod.Spec.ImagePullSecrets, 1) | ||
require.Equal(t, "secret", pod.Spec.ImagePullSecrets[0].Name) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
pkg/apis/scheduler/v1alpha1/pod/resources/zz_generated.deepcopy.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.