Skip to content

Commit 85c8656

Browse files
committed
Address review comments (to be squashed before merging)
1 parent 7f36c57 commit 85c8656

3 files changed

Lines changed: 25 additions & 26 deletions

File tree

lib/resourcebuilder/core.go

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"sigs.k8s.io/kustomize/kyaml/yaml"
1010

1111
corev1 "k8s.io/api/core/v1"
12-
apierrors "k8s.io/apimachinery/pkg/api/errors"
1312
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1413
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1514
"k8s.io/apimachinery/pkg/labels"
@@ -49,7 +48,6 @@ func (b *builder) modifyConfigMap(ctx context.Context, cm *corev1.ConfigMap) err
4948
if err != nil {
5049
return fmt.Errorf("unable to observe TLS configuration: %v", err)
5150
}
52-
5351
if !minTLSFound && !ciphersFound {
5452
klog.V(2).Infof("ConfigMap %s/%s: no TLS configuration found, skipping", cm.Namespace, cm.Name)
5553
return nil
@@ -69,13 +67,9 @@ func (b *builder) modifyConfigMap(ctx context.Context, cm *corev1.ConfigMap) err
6967
}
7068

7169
// Check if this is a GenericOperatorConfig by checking the kind field
72-
kind, err := rnode.GetString("kind")
73-
if err != nil {
74-
klog.V(4).Infof("ConfigMap's %q kind accessing failed: %v", key, err)
75-
continue
76-
}
70+
kind := rnode.GetKind()
7771
if kind != "GenericOperatorConfig" {
78-
klog.V(4).Infof("ConfigMap's %q entry is not a GenericOperatorConfig, skiping this entry", key)
72+
klog.V(4).Infof("ConfigMap's %q entry is not a GenericOperatorConfig, skipping this entry", key)
7973
continue
8074
}
8175

@@ -109,18 +103,6 @@ func (b *builder) modifyConfigMap(ctx context.Context, cm *corev1.ConfigMap) err
109103
// using ObserveTLSSecurityProfile and extracts minTLSVersion and cipherSuites.
110104
// minTLSVersion string, minTLSFound bool, cipherSuites []string, ciphersFound bool, err error
111105
func (b *builder) observeTLSConfiguration(ctx context.Context, cm *corev1.ConfigMap) (string, bool, []string, bool, error) {
112-
// First check if the APIServer cluster resource exists
113-
_, err := b.configClientv1.APIServers().Get(ctx, "cluster", metav1.GetOptions{})
114-
if err != nil {
115-
if apierrors.IsNotFound(err) {
116-
klog.V(2).Infof("ConfigMap %s/%s: APIServer cluster resource not found, skipping TLS injection", cm.Namespace, cm.Name)
117-
return "", false, nil, false, nil
118-
}
119-
// For transient API failures (network errors, timeouts, etc.), log at higher severity
120-
klog.Warningf("ConfigMap %s/%s: failed to get APIServer cluster resource (transient failure), skipping TLS injection: %v", cm.Namespace, cm.Name, err)
121-
return "", false, nil, false, err
122-
}
123-
124106
// Create a lister adapter for ObserveTLSSecurityProfile
125107
lister := &apiServerListerAdapter{
126108
client: b.configClientv1.APIServers(),
@@ -138,13 +120,27 @@ func (b *builder) observeTLSConfiguration(ctx context.Context, cm *corev1.Config
138120
if len(errs) > 0 {
139121
// Log errors but continue - ObserveTLSSecurityProfile is tolerant of missing config
140122
for _, err := range errs {
141-
klog.V(2).Infof("ConfigMap %s/%s: error observing TLS profile: %v", cm.Namespace, cm.Name, err)
123+
klog.Errorf("ConfigMap %s/%s: error observing TLS profile: %v", cm.Namespace, cm.Name, err)
142124
}
143125
}
144126

145127
// Extract the TLS settings from the observed config
146-
minTLSVersion, minTLSFound, _ := unstructured.NestedString(observedConfig, "servingInfo", "minTLSVersion")
128+
minTLSVersion, minTLSFound, err := unstructured.NestedString(observedConfig, "servingInfo", "minTLSVersion")
129+
if err != nil {
130+
// This error is unlikely to happen unless unstructured.NestedString is buggy.
131+
// From unstructured.NestedString's description:
132+
// "Returns false if value is not found and an error if not a string."
133+
// The observedConfig's servingInfo.minTLSVersion is of a string type
134+
return "", false, nil, false, err
135+
}
147136
cipherSuites, ciphersFound, _ := unstructured.NestedStringSlice(observedConfig, "servingInfo", "cipherSuites")
137+
if err != nil {
138+
// This error is unlikely to happen unless unstructured.NestedStringSlice is buggy
139+
// From unstructured.NestedString's description:
140+
// "Returns false if value is not found and an error if not a []interface{} or contains non-string items in the slice."
141+
// The observedConfig's servingInfo.minTLSVersion is of a string type
142+
return "", false, nil, false, err
143+
}
148144

149145
// Sort cipher suites for consistent comparison
150146
if ciphersFound && len(cipherSuites) > 0 {

lib/resourcebuilder/core_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,17 @@ func TestModifyConfigMap(t *testing.T) {
357357
},
358358
},
359359
{
360-
name: "ConfigMap with annotation and Data - APIServer not found",
360+
name: "ConfigMap with annotation and Data - APIServer not found - default TLS configuration expected",
361361
configMap: makeConfigMap(true, map[string]string{
362362
genericOperatorConfigCMKey: makeGenericOperatorConfigYAML(testCipherSuites, tlsVersion12),
363363
}),
364364
apiServer: nil,
365365
expectError: false,
366366
validateConfigMap: func(t *testing.T, original, modified *corev1.ConfigMap) {
367-
if err := validateConfigMapsEqual(original, modified); err != nil {
367+
defaultTLSConfigMap := makeConfigMap(true, map[string]string{
368+
genericOperatorConfigCMKey: makeGenericOperatorConfigYAML(defaultCipherSuites, tlsVersion12),
369+
})
370+
if err := validateConfigMapsEqual(defaultTLSConfigMap, modified); err != nil {
368371
t.Fatalf("validation failed: %v", err)
369372
}
370373
},

lib/resourcebuilder/resourcebuilder_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ func TestModifyConfigMapWithBuilder(t *testing.T) {
6767
configObjs = append(configObjs, tt.apiServer)
6868
fmt.Printf("tt.apiServer: %v\n", tt.apiServer.Spec.TLSSecurityProfile.Custom.TLSProfileSpec)
6969
}
70-
fakeConfigClient := fakeconfigclientv1.NewSimpleClientset(configObjs...)
70+
fakeConfigClient := fakeconfigclientv1.NewClientset(configObjs...)
7171

7272
// Create fake kubernetes client
73-
fakeKubeClient := fakekubernetes.NewSimpleClientset()
73+
fakeKubeClient := fakekubernetes.NewClientset()
7474

7575
// Marshal ConfigMap to YAML bytes
7676
configMapYAML, err := yaml.Marshal(tt.configMap)

0 commit comments

Comments
 (0)