Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions pkg/operator/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -2179,16 +2179,23 @@ func (optr *Operator) getImageRegistryPullSecrets() ([]byte, error) {

clusterPullSecretRaw := clusterPullSecret.Data[corev1.DockerConfigJsonKey]

// Add in the cluster pull secret to the JSON map, but convert it to kubernetes.io/dockercfg first
// as the global pull secret is of type kubernetes.io/dockerconfigjson
clusterPullSecretRawOld, err := ctrlcommon.ConvertSecretTodockercfg(clusterPullSecretRaw)
if err != nil {
return nil, fmt.Errorf("failed to convert global pull secret to old format: %w", err)
}
// Handle empty pull-secret gracefully
// Check if the pull-secret is empty or just contains "{}"
// This can happen when users set an empty pull-secret: `oc set data secret/pull-secret '.dockerconfigjson={}'`
if len(clusterPullSecretRaw) > 0 && string(bytes.TrimSpace(clusterPullSecretRaw)) != "{}" {
// Add in the cluster pull secret to the JSON map, but convert it to kubernetes.io/dockercfg first
// as the global pull secret is of type kubernetes.io/dockerconfigjson
clusterPullSecretRawOld, err := ctrlcommon.ConvertSecretTodockercfg(clusterPullSecretRaw)
if err != nil {
return nil, fmt.Errorf("failed to convert global pull secret to old format: %w", err)
}

err = ctrlcommon.MergeDockerConfigstoJSONMap(clusterPullSecretRawOld, dockerConfigJSON.Auths)
if err != nil {
return nil, fmt.Errorf("failed to merge global pull secret: %w", err)
err = ctrlcommon.MergeDockerConfigstoJSONMap(clusterPullSecretRawOld, dockerConfigJSON.Auths)
if err != nil {
return nil, fmt.Errorf("failed to merge global pull secret: %w", err)
}
} else {
klog.V(4).Infof("Skipping merge of empty global pull secret")
}

// Add in a default image registry route for first boot cases; this route won't be provided during a pull
Expand Down
10 changes: 10 additions & 0 deletions pkg/secrets/secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ type: kubernetes.io/dockercfg`
bytes: []byte(`{"auths":{}}`),
expected: &DockerConfigJSON{Auths: DockerConfig{}},
},
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Thanks for adding these test cases!

name: "Empty JSON object without auths key",
bytes: []byte(`{}`),
expected: &DockerConfigJSON{Auths: nil},
},
{
name: "JSON null literal",
bytes: []byte(`null`),
errExpected: true,
},
{
name: "Invalid K8s object bytes",
bytes: []byte(`{"kind":"ConfigMap","apiVersion":"v1","metadata":{"name":"configmap"},"data":{"key":"value"}}`),
Expand Down