Skip to content

Commit 0da9683

Browse files
Deployment annotations, runtimeClassName override and fs policy change
We are using config.spec.unsupportedConfigOverrides to allow users to override image registry runtimeClass and annotations. This commit also uses OnRootMismatch for fsGroupChangePolicy in the registry deployment.
1 parent 39a82aa commit 0da9683

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

pkg/resource/configoverrides.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package resource
2+
3+
// ConfigOverrides holds data users can set to override default object configurations created
4+
// by this operator. This is stored in the registry Config.Spec.UnsupportedConfigOverrides.
5+
type ConfigOverrides struct {
6+
Deployment *DeploymentOverrides `json:"deployment,omitempty"`
7+
}
8+
9+
// DeploymentOverrides holds items that can be overwriten in the image registry deployment.
10+
type DeploymentOverrides struct {
11+
Annotations map[string]string `json:"annotations,omitempty"`
12+
RuntimeClassName *string `json:"runtimeClassName,omitempty"`
13+
}

pkg/resource/deployment.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package resource
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"os"
78

@@ -155,6 +156,23 @@ func (gd *generatorDeployment) expected() (runtime.Object, error) {
155156
},
156157
}
157158

159+
rawoverrides := gd.cr.Spec.UnsupportedConfigOverrides.Raw
160+
if len(rawoverrides) > 0 {
161+
var overrides ConfigOverrides
162+
if err := json.Unmarshal(rawoverrides, &overrides); err != nil {
163+
return nil, fmt.Errorf("invalid unsupportedConfigOverrides: %w", err)
164+
}
165+
166+
depoverrides := overrides.Deployment
167+
if depoverrides != nil {
168+
deploy.Spec.Template.Spec.RuntimeClassName = depoverrides.RuntimeClassName
169+
for key, val := range depoverrides.Annotations {
170+
deploy.Annotations[key] = val
171+
deploy.Spec.Template.Annotations[key] = val
172+
}
173+
}
174+
}
175+
158176
dgst, err := strategy.Checksum(deploy)
159177
if err != nil {
160178
return nil, err

pkg/resource/podtemplatespec.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ func generateSecurityContext(coreClient coreset.CoreV1Interface, namespace strin
9595
return nil, fmt.Errorf("unable to parse annotation %s in namespace %q: %s", defaults.SupplementalGroupsAnnotation, namespace, err)
9696
}
9797

98+
fsGroupChangePolicy := corev1.FSGroupChangeOnRootMismatch
9899
return &corev1.PodSecurityContext{
99-
FSGroup: &gid,
100+
FSGroup: &gid,
101+
FSGroupChangePolicy: &fsGroupChangePolicy,
100102
}, nil
101103
}
102104

pkg/resource/podtemplatespec_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ func TestMakePodTemplateSpec(t *testing.T) {
173173
}
174174
}
175175

176+
fsGroupChangePolicy := pod.Spec.SecurityContext.FSGroupChangePolicy
177+
if fsGroupChangePolicy == nil || *fsGroupChangePolicy != corev1.FSGroupChangeOnRootMismatch {
178+
t.Errorf("expected FSGroupChangePolicy to be set to OnRootMismatch")
179+
}
176180
}
177181

178182
func verifyVolume(volume corev1.Volume, expected *volumeMount, t *testing.T) {

0 commit comments

Comments
 (0)