@@ -40,13 +40,15 @@ type tlsConfig struct {
4040 cipherSuites optional [[]string ]
4141}
4242
43+ // modifyConfigMap sets/clears minTLSVersion and cipherSuites in the CM's data entries if
44+ // * ConfigMapInjectTLSAnnotation is "true"
45+ // * Data entry kind is GenericOperatorConfig or GenericControllerConfig
4346func (b * builder ) modifyConfigMap (ctx context.Context , cm * corev1.ConfigMap ) error {
4447 // Check for TLS injection annotation
4548 if value , ok := cm .Annotations [ConfigMapInjectTLSAnnotation ]; ! ok || value != "true" {
4649 return nil
4750 }
48-
49- klog .V (2 ).Infof ("ConfigMap %s/%s has %s annotation set to true" , cm .Namespace , cm .Name , ConfigMapInjectTLSAnnotation )
51+ klog .V (2 ).Infof ("ConfigMap %s/%s has annotation %s: true" , cm .Namespace , cm .Name , ConfigMapInjectTLSAnnotation )
5052
5153 // Empty data, nothing to inject into
5254 if cm .Data == nil {
@@ -71,7 +73,7 @@ func (b *builder) modifyConfigMap(ctx context.Context, cm *corev1.ConfigMap) err
7173 klog .V (4 ).Infof ("ConfigMap %s/%s: observed minTLSVersion=%v, cipherSuites=%v" ,
7274 cm .Namespace , cm .Name , minTLSLog , cipherSuitesLog )
7375
74- // Process each data entry that contains GenericOperatorConfig
76+ // Process each data key
7577 for key , value := range cm .Data {
7678 klog .V (4 ).Infof ("Processing %q key" , key )
7779 // Parse YAML into RNode to preserve formatting and field order
@@ -82,18 +84,19 @@ func (b *builder) modifyConfigMap(ctx context.Context, cm *corev1.ConfigMap) err
8284 continue
8385 }
8486
85- // Check if this is a supported config kind
87+ // Check if this is a supported data node kind
88+ rnodeKind := rnode .GetKind ()
8689 switch {
87- case rnode . GetKind () == "GenericOperatorConfig" && rnode .GetApiVersion () == operatorv1alpha1 .GroupVersion .String ():
88- case rnode . GetKind () == "GenericControllerConfig" && rnode .GetApiVersion () == configv1 .GroupVersion .String ():
90+ case rnodeKind == "GenericOperatorConfig" && rnode .GetApiVersion () == operatorv1alpha1 .GroupVersion .String ():
91+ case rnodeKind == "GenericControllerConfig" && rnode .GetApiVersion () == configv1 .GroupVersion .String ():
8992 default :
9093 klog .V (4 ).Infof ("ConfigMap's %q entry is not a supported config type. Only GenericOperatorConfig (%v) and GenericControllerConfig (%v) are. Skipping this entry" , key , operatorv1alpha1 .GroupVersion .String (), configv1 .GroupVersion .String ())
9194 continue
9295 }
9396
94- klog .V (2 ).Infof ("ConfigMap %s/%s processing GenericOperatorConfig in key %s" , cm .Namespace , cm .Name , key )
97+ klog .V (2 ).Infof ("ConfigMap %s/%s processing %s in key %s" , cm .Namespace , cm .Name , rnodeKind , key )
9598
96- // Inject TLS settings into the GenericOperatorConfig while preserving structure
99+ // Inject TLS settings into the data node while preserving structure
97100 if err := updateRNodeWithTLSSettings (rnode , tlsConf ); err != nil {
98101 return fmt .Errorf ("failed to inject the TLS configuration: %v" , err )
99102 }
@@ -106,7 +109,7 @@ func (b *builder) modifyConfigMap(ctx context.Context, cm *corev1.ConfigMap) err
106109
107110 // Update the ConfigMap data entry with the modified YAML
108111 cm .Data [key ] = modifiedYAML
109- klog .V (2 ).Infof ("ConfigMap %s/%s updated GenericOperatorConfig with TLS profile in key %s" , cm .Namespace , cm .Name , key )
112+ klog .V (2 ).Infof ("ConfigMap %s/%s updated TLS profile of %s in key %s" , cm .Namespace , cm .Name , rnodeKind , key )
110113 }
111114 return nil
112115}
@@ -153,7 +156,8 @@ func (b *builder) observeTLSConfiguration(ctx context.Context, cm *corev1.Config
153156 return config , nil
154157}
155158
156- // updateRNodeWithTLSSettings injects TLS settings into a GenericOperatorConfig RNode while preserving structure.
159+ // updateRNodeWithTLSSettings injects TLS settings into an RNode while preserving structure.
160+ // Assumes a GenericOperatorConfig or GenericControllerConfig schema.
157161// If a field in tlsConf is not found, the corresponding field will be deleted from the RNode.
158162func updateRNodeWithTLSSettings (rnode * yaml.RNode , tlsConf * tlsConfig ) error {
159163 servingInfo , err := rnode .Pipe (yaml .LookupCreate (yaml .MappingNode , "servingInfo" ))
0 commit comments