this scripts delete redundant registry-keys in the workloads
the steps are like this
- find the relevant workload (deployment|statefulset|daemonset) that contains
registry-keys. the logic is implemented by following line
bash
has_registry_key=$(kubectl get $resource_type $resource_name -n $namespace -o jsonpath='{.spec.template.spec.imagePullSecrets[*].name}' | grep -E '^registry-key$' || true)- generate a tmpfile with the updated field and run it with kubectl patch. the logic is implemented by following line
bash
kubectl patch $resource_type $resource_name -n $namespace --patch-file $temp_file --type mergenote that --type is specified as merge, the explanation between stratigic(default) and merge can be found in the official documentation