Skip to content

Commit 4c36707

Browse files
committed
[Feature] ArangoProfile Selectors
1 parent 8be3599 commit 4c36707

23 files changed

+808
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- (Feature) Discover Namespace in DebugPackage from K8S
1010
- (Feature) Expose Force CRD Install option
1111
- (Maintenance) Move Container utils functions
12+
- (Feature) ArangoProfile Selectors
1213

1314
## [1.2.39](https://github.com/arangodb/kube-arangodb/tree/1.2.39) (2024-03-11)
1415
- (Feature) Extract Scheduler API

docs/api/ArangoMLExtension.V1Alpha1.md

+8
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ Default Value: `false`
7171

7272
***
7373

74+
### .spec.deployment.imagePullSecrets
75+
76+
Type: `array` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.39/pkg/apis/scheduler/v1alpha1/pod/resources/image.go#L36)</sup>
77+
78+
ImagePullSecrets define Secrets used to pull Image from registry
79+
80+
***
81+
7482
### .spec.deployment.labels
7583

7684
Type: `object` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.39/pkg/apis/scheduler/v1alpha1/pod/resources/metadata.go#L39)</sup>

docs/api/ArangoProfile.V1Alpha1.md

+16
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ title: ArangoProfile V1Alpha1
88

99
## Spec
1010

11+
### .spec.selectors.label
12+
13+
Type: `meta.LabelSelector` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.39/pkg/apis/scheduler/v1alpha1/profile_selectors.go#L31)</sup>
14+
15+
Label keeps information about label selector
16+
17+
***
18+
1119
### .spec.template.container.all.env
1220

1321
Type: `core.EnvVar` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.39/pkg/apis/scheduler/v1alpha1/container/resources/environments.go#L36)</sup>
@@ -281,6 +289,14 @@ Default Value: `false`
281289

282290
***
283291

292+
### .spec.template.pod.imagePullSecrets
293+
294+
Type: `array` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.39/pkg/apis/scheduler/v1alpha1/pod/resources/image.go#L36)</sup>
295+
296+
ImagePullSecrets define Secrets used to pull Image from registry
297+
298+
***
299+
284300
### .spec.template.pod.labels
285301

286302
Type: `object` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.39/pkg/apis/scheduler/v1alpha1/pod/resources/metadata.go#L39)</sup>

pkg/apis/scheduler/v1alpha1/container/resources/resources.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ func (r *Resources) Apply(_ *core.PodTemplateSpec, template *core.Container) err
4242
return nil
4343
}
4444

45-
template.Resources = r.GetResources()
45+
res := r.GetResources()
46+
47+
template.Resources.Limits = kresources.UpscaleContainerResourceList(template.Resources.Limits, res.Limits)
48+
template.Resources.Requests = kresources.UpscaleContainerResourceList(template.Resources.Requests, res.Requests)
4649

4750
return nil
4851
}

pkg/apis/scheduler/v1alpha1/container/resources/volume_mounts.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (v *VolumeMounts) Apply(_ *core.PodTemplateSpec, container *core.Container)
4242

4343
obj := v.DeepCopy()
4444

45-
container.VolumeMounts = obj.VolumeMounts
45+
container.VolumeMounts = kresources.MergeVolumeMounts(container.VolumeMounts, obj.VolumeMounts...)
4646

4747
return nil
4848
}

pkg/apis/scheduler/v1alpha1/pod/definition.go

+14
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ type Pod struct {
3434
// Metadata keeps the metadata settings for Pod
3535
*schedulerPodResourcesApi.Metadata `json:",inline"`
3636

37+
// Image keeps the image information
38+
*schedulerPodResourcesApi.Image `json:",inline"`
39+
3740
// Scheduling keeps the scheduling information
3841
*schedulerPodResourcesApi.Scheduling `json:",inline"`
3942

@@ -65,6 +68,7 @@ func (a *Pod) With(other *Pod) *Pod {
6568

6669
return &Pod{
6770
Scheduling: a.Scheduling.With(other.Scheduling),
71+
Image: a.Image.With(other.Image),
6872
Namespace: a.Namespace.With(other.Namespace),
6973
Security: a.Security.With(other.Security),
7074
Volumes: a.Volumes.With(other.Volumes),
@@ -80,6 +84,7 @@ func (a *Pod) Apply(template *core.PodTemplateSpec) error {
8084

8185
return shared.WithErrors(
8286
a.Scheduling.Apply(template),
87+
a.Image.Apply(template),
8388
a.Namespace.Apply(template),
8489
a.Security.Apply(template),
8590
a.Volumes.Apply(template),
@@ -96,6 +101,14 @@ func (a *Pod) GetSecurity() *schedulerPodResourcesApi.Security {
96101
return a.Security
97102
}
98103

104+
func (a *Pod) GetImage() *schedulerPodResourcesApi.Image {
105+
if a == nil {
106+
return nil
107+
}
108+
109+
return a.Image
110+
}
111+
99112
func (a *Pod) GetScheduling() *schedulerPodResourcesApi.Scheduling {
100113
if a == nil {
101114
return nil
@@ -142,6 +155,7 @@ func (a *Pod) Validate() error {
142155
}
143156
return shared.WithErrors(
144157
a.Scheduling.Validate(),
158+
a.Image.Validate(),
145159
a.Namespace.Validate(),
146160
a.Security.Validate(),
147161
a.Volumes.Validate(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 resources
22+
23+
import (
24+
core "k8s.io/api/core/v1"
25+
26+
"github.com/arangodb/kube-arangodb/pkg/apis/scheduler/v1alpha1/interfaces"
27+
shared "github.com/arangodb/kube-arangodb/pkg/apis/shared"
28+
)
29+
30+
type ImagePullSecrets []string
31+
32+
var _ interfaces.Pod[Image] = &Image{}
33+
34+
type Image struct {
35+
// ImagePullSecrets define Secrets used to pull Image from registry
36+
ImagePullSecrets ImagePullSecrets `json:"imagePullSecrets,omitempty"`
37+
}
38+
39+
func (i *Image) Apply(pod *core.PodTemplateSpec) error {
40+
if i == nil {
41+
return nil
42+
}
43+
44+
for _, secret := range i.ImagePullSecrets {
45+
if hasImagePullSecret(pod.Spec.ImagePullSecrets, secret) {
46+
continue
47+
}
48+
49+
pod.Spec.ImagePullSecrets = append(pod.Spec.ImagePullSecrets, core.LocalObjectReference{
50+
Name: secret,
51+
})
52+
}
53+
54+
return nil
55+
}
56+
57+
func (i *Image) With(other *Image) *Image {
58+
if i == nil && other == nil {
59+
return nil
60+
}
61+
62+
if other == nil {
63+
return i.DeepCopy()
64+
}
65+
66+
return other.DeepCopy()
67+
}
68+
69+
func (i *Image) Validate() error {
70+
if i == nil {
71+
return nil
72+
}
73+
74+
return shared.WithErrors(
75+
shared.PrefixResourceErrors("pullSecrets", shared.ValidateList(i.ImagePullSecrets, shared.ValidateResourceName)),
76+
)
77+
}
78+
79+
func hasImagePullSecret(secrets []core.LocalObjectReference, secret string) bool {
80+
for _, sec := range secrets {
81+
if sec.Name == secret {
82+
return true
83+
}
84+
}
85+
86+
return false
87+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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 resources
22+
23+
import (
24+
"testing"
25+
26+
"github.com/stretchr/testify/require"
27+
core "k8s.io/api/core/v1"
28+
)
29+
30+
func applyImage(t *testing.T, template *core.PodTemplateSpec, ns ...*Image) func(in func(t *testing.T, pod *core.PodTemplateSpec)) {
31+
var i *Image
32+
33+
for _, n := range ns {
34+
require.NoError(t, n.Validate())
35+
36+
i = i.With(n)
37+
38+
require.NoError(t, i.Validate())
39+
}
40+
41+
template = template.DeepCopy()
42+
43+
if template == nil {
44+
template = &core.PodTemplateSpec{}
45+
}
46+
47+
require.NoError(t, i.Apply(template))
48+
49+
return func(in func(t *testing.T, spec *core.PodTemplateSpec)) {
50+
t.Run("Validate", func(t *testing.T) {
51+
in(t, template)
52+
})
53+
}
54+
}
55+
56+
func Test_Image(t *testing.T) {
57+
t.Run("With Nil", func(t *testing.T) {
58+
applyImage(t, nil, nil)(func(t *testing.T, pod *core.PodTemplateSpec) {
59+
require.Len(t, pod.Spec.ImagePullSecrets, 0)
60+
})
61+
})
62+
t.Run("With Empty", func(t *testing.T) {
63+
applyImage(t, &core.PodTemplateSpec{})(func(t *testing.T, pod *core.PodTemplateSpec) {
64+
require.Len(t, pod.Spec.ImagePullSecrets, 0)
65+
})
66+
})
67+
t.Run("With PS", func(t *testing.T) {
68+
applyImage(t, &core.PodTemplateSpec{}, &Image{
69+
ImagePullSecrets: []string{
70+
"secret",
71+
},
72+
})(func(t *testing.T, pod *core.PodTemplateSpec) {
73+
require.Len(t, pod.Spec.ImagePullSecrets, 1)
74+
require.Equal(t, "secret", pod.Spec.ImagePullSecrets[0].Name)
75+
})
76+
})
77+
t.Run("With PS2", func(t *testing.T) {
78+
applyImage(t, &core.PodTemplateSpec{}, &Image{
79+
ImagePullSecrets: []string{
80+
"secret",
81+
"secret",
82+
},
83+
})(func(t *testing.T, pod *core.PodTemplateSpec) {
84+
require.Len(t, pod.Spec.ImagePullSecrets, 1)
85+
require.Equal(t, "secret", pod.Spec.ImagePullSecrets[0].Name)
86+
})
87+
})
88+
}

pkg/apis/scheduler/v1alpha1/pod/resources/service_account.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ func (s *ServiceAccount) Apply(template *core.PodTemplateSpec) error {
4646
c := s.DeepCopy()
4747

4848
template.Spec.ServiceAccountName = c.ServiceAccountName
49-
template.Spec.AutomountServiceAccountToken = c.AutomountServiceAccountToken
49+
if c.AutomountServiceAccountToken != nil {
50+
template.Spec.AutomountServiceAccountToken = c.AutomountServiceAccountToken
51+
}
5052

5153
return nil
5254
}

pkg/apis/scheduler/v1alpha1/pod/resources/volumes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (v *Volumes) Apply(template *core.PodTemplateSpec) error {
4343

4444
obj := v.DeepCopy()
4545

46-
template.Spec.Volumes = obj.Volumes
46+
template.Spec.Volumes = kresources.MergeVolumes(template.Spec.Volumes, obj.Volumes...)
4747

4848
return nil
4949
}

pkg/apis/scheduler/v1alpha1/pod/resources/zz_generated.deepcopy.go

+41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/scheduler/v1alpha1/pod/zz_generated.deepcopy.go

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)