Skip to content

Commit 70b9d62

Browse files
committed
feat(csi-snapshot-controller-operator): inject centralized TLS configuration
Mount a configmap with an operator config injected with the HCP TLS security profile.
1 parent 8a04628 commit 70b9d62

4 files changed

Lines changed: 63 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: csi-snapshot-controller-operator-config
5+
data:
6+
config.yaml: ""

control-plane-operator/controllers/hostedcontrolplane/v2/assets/csi-snapshot-controller-operator/deployment.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ spec:
2121
- args:
2222
- start
2323
- -v=2
24+
- --config=/var/run/configmaps/config/config.yaml
25+
- --terminate-on-files=/var/run/configmaps/config/config.yaml
2426
- --guest-kubeconfig=/etc/guest-kubeconfig/kubeconfig
2527
env:
2628
- name: OPERAND_IMAGE
@@ -49,6 +51,9 @@ spec:
4951
volumeMounts:
5052
- mountPath: /etc/guest-kubeconfig
5153
name: guest-kubeconfig
54+
- mountPath: /var/run/configmaps/config
55+
name: config
56+
readOnly: true
5257
securityContext:
5358
runAsNonRoot: true
5459
seccompProfile:
@@ -58,3 +63,6 @@ spec:
5863
- name: guest-kubeconfig
5964
secret:
6065
secretName: service-network-admin-kubeconfig
66+
- configMap:
67+
name: csi-snapshot-controller-operator-config
68+
name: config

control-plane-operator/controllers/hostedcontrolplane/v2/snapshotcontroller/component.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ func NewComponent() component.ControlPlaneComponent {
4242
return component.NewDeploymentComponent(ComponentName, &snapshotController{}).
4343
WithAdaptFunction(adaptDeployment).
4444
WithPredicate(isStorageAndCSIManaged).
45+
WithManifestAdapter(
46+
"controller-config.yaml",
47+
component.WithAdaptFunction(adaptControllerConfig),
48+
).
4549
WithDependencies(oapiv2.ComponentName).
4650
InjectAvailabilityProberContainer(podspec.AvailabilityProberOpts{
4751
KubeconfigVolumeName: "guest-kubeconfig",

control-plane-operator/controllers/hostedcontrolplane/v2/snapshotcontroller/deployment.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
package snapshotcontroller
22

33
import (
4+
"encoding/json"
5+
"fmt"
46
"strconv"
57

8+
"github.com/openshift/hypershift/support/config"
69
component "github.com/openshift/hypershift/support/controlplane-component"
710
"github.com/openshift/hypershift/support/podspec"
811

12+
configv1 "github.com/openshift/api/config/v1"
13+
914
appsv1 "k8s.io/api/apps/v1"
1015
corev1 "k8s.io/api/core/v1"
16+
17+
"sigs.k8s.io/yaml"
1118
)
1219

1320
func adaptDeployment(cpContext component.WorkloadContext, deployment *appsv1.Deployment) error {
@@ -31,3 +38,41 @@ func adaptDeployment(cpContext component.WorkloadContext, deployment *appsv1.Dep
3138

3239
return nil
3340
}
41+
42+
func adaptControllerConfig(cpContext component.WorkloadContext, cm *corev1.ConfigMap) error {
43+
profile := cpContext.HCP.Spec.Configuration.GetTLSSecurityProfile()
44+
controllerConfig := configv1.GenericControllerConfig{
45+
ServingInfo: configv1.HTTPServingInfo{
46+
ServingInfo: configv1.ServingInfo{
47+
BindAddress: ":8443",
48+
CipherSuites: config.CipherSuites(profile),
49+
MinTLSVersion: config.MinTLSVersion(profile),
50+
},
51+
},
52+
}
53+
54+
asJSON, err := json.Marshal(controllerConfig)
55+
if err != nil {
56+
return fmt.Errorf("failed to json marshal config: %w", err)
57+
}
58+
59+
asMap := map[string]any{}
60+
if err := json.Unmarshal(asJSON, &asMap); err != nil {
61+
return fmt.Errorf("failed to json unmarshal config: %w", err)
62+
}
63+
64+
asMap["apiVersion"] = configv1.GroupVersion.String()
65+
asMap["kind"] = "GenericControllerConfig"
66+
67+
data, err := yaml.Marshal(asMap)
68+
if err != nil {
69+
return fmt.Errorf("failed to yaml marshal config: %w", err)
70+
}
71+
72+
if cm.Data == nil {
73+
cm.Data = map[string]string{}
74+
}
75+
76+
cm.Data["config.yaml"] = string(data)
77+
return nil
78+
}

0 commit comments

Comments
 (0)