-
Notifications
You must be signed in to change notification settings - Fork 253
HIVE-2891: Add new HiveConfig field "HiveImagePullSecretRef" #2734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
@dlom: This pull request references HIVE-2891 which is a valid jira issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dlom The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@dlom: This pull request references HIVE-2891 which is a valid jira issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2734 +/- ##
==========================================
- Coverage 50.16% 50.03% -0.14%
==========================================
Files 288 288
Lines 34065 34240 +175
==========================================
+ Hits 17090 17133 +43
- Misses 15626 15756 +130
- Partials 1349 1351 +2
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this PR also needs to touch your previous efforts to reference this secret from the hive-operator pod. We discussed how copying imagePullSecrets
across namespaces will end us up with a reference to a dockercfg Secret that doesn't (and shouldn't) exist in the destination namespace. So I think we need to refactor all of those places to simply add the value of hiveConfig.hiveImagePullSecretRef
to the imagePullSecrets
of controllers, admission, imageset, provision, and deprovision.
We also need to address copying the Secret to the targetNamespace
iff that namespace is different from where hive-operator is running.
Once all of that is done, I think we can revert some of your additions that look up the current pod -- they should no longer be needed. (However, I like the way you rolled up sharedPodConfig; I would like to keep that for tolerations/nodeSelector.)
src := types.NamespacedName{Name: secretName, Namespace: srcNamespace} | ||
dest := types.NamespacedName{Name: secretName, Namespace: destNamespace} | ||
|
||
// TODO: cross-NS ownership reference? is that even possible? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not. However, we should parent it to the CD. There is precedent, and a handy helper function. See for example how we do this for the pull secret.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still haven't figured this one out. Did you link the wrong thing, or am I blind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bleh, sorry, correct reference.
As we discussed, "controller reference" is not the same as "owner reference", and I think we want the former. The purpose is for the Secret to automatically get deleted/garbage-collected when the parent (the CD) goes away.
86bb5ee
to
8744666
Compare
@2uasimojo after blindly forging ahead on this all day, I don't think this is possible either. The |
Per our Meet™, clarified summary:
|
ce397ca
to
f484d4c
Compare
I've done an initial smoke test on this, with the operator, controllers, and CD all being in different non-default namespaces. The operator uses a label on the controller-level secret to clean up if the controllers move, and the CDs each get an individually named secret copy that is owned by the CD |
/test e2e |
/test e2e Actual test succeeded; we flaked afterward. |
@@ -41,6 +41,14 @@ type HiveConfigSpec struct { | |||
// +optional | |||
GlobalPullSecretRef *corev1.LocalObjectReference `json:"globalPullSecretRef,omitempty"` | |||
|
|||
// HiveImagePullSecretRef is used to specify a pull secret that can be used to pull Hive's own image. | |||
// If hive has been deployed from a private registry, cluster installations will not succeed unless | |||
// this reference is specified. This secret must live in Hive's TargetNamespace. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this true, or does it need to live in the namespace with hive-operator?
// GetImagePullSecretName returns name for image pull secret name per cluster deployment | ||
func GetImagePullSecretName(cd *hivev1.ClusterDeployment) string { | ||
return apihelpers.GetResourceName(cd.Name, hiveImagePullSecretSuffix) | ||
} | ||
|
||
// GetImagePullSecretNameForDeprovision returns name for image pull secret name per cluster deprovision | ||
func GetImagePullSecretNameForDeprovision(cd *hivev1.ClusterDeprovision) string { | ||
return apihelpers.GetResourceName(cd.Name, hiveImagePullSecretSuffix) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can DRY these by making the param a meta.Object and using GetName() on it.
(Moot if you copy the Secret down just once with its original name, as noted.)
// NOTE: This secret will be copied into the namespace of every ClusterDeployment, overwriting any secret | ||
// with the same name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is true either, as it looks like you're naming those Secrets after the cd/deprovision.
Though thinking about it, I think I like this idea better. There's nothing stopping multiple CDs being created in the same namespace, and we would rather have just one copy of this pull secret per namespace.
@@ -717,6 +719,7 @@ func completeAWSDeprovisionJob(req *hivev1.ClusterDeprovision, job *batchv1.Job) | |||
job.Spec.Template.Spec.InitContainers = initContainers | |||
job.Spec.Template.Spec.Containers = containers | |||
job.Spec.Template.Spec.Volumes = volumes | |||
job.Spec.Template.Spec.ImagePullSecrets = append(job.Spec.Template.Spec.ImagePullSecrets, corev1.LocalObjectReference{Name: constants.GetImagePullSecretNameForDeprovision(req)}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two things:
- Why not do this in the calling func instead of here? I think all the other pieces are being done per-
complete*DeprovisionJob()
method because they can be different. (If you find otherwise, I would be receptive to a separate PR that pulls them out.) But this should always be the same, yah? - This is working because we happen to give the ClusterDeprovision the same name as the ClusterDeployment. But it reads as if we're potentially referencing a different Secret -- and one we haven't copied in. I can see that it would be painful to get the CD down to these funcs, so I'm okay leaving the logic as is, but I would like to see a comment that calls out that it's relying on those two things having the same name. [Later] But moot if we're using the original Secret name as noted above.
// hive namespace (named in HiveConfig.Spec.TargetNamespace). We use this to identify secrets in | ||
// namespaces that were *previously* the configured TargetNamespace so we can clean | ||
// them up. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we not just using owner references? I guess they would have to be on one of the Deployments/StatefulSets, but that should work, shouldn't it?
if hiveConfigHasValidImagePullSecretReference(instance) { | ||
hiveDeployment.Spec.Template.Spec.ImagePullSecrets = append(hiveDeployment.Spec.Template.Spec.ImagePullSecrets, *instance.Spec.HiveImagePullSecretRef) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a thought, if you made the func return the ref instead of just checking for it, you could do something like:
if hiveConfigHasValidImagePullSecretReference(instance) { | |
hiveDeployment.Spec.Template.Spec.ImagePullSecrets = append(hiveDeployment.Spec.Template.Spec.ImagePullSecrets, *instance.Spec.HiveImagePullSecretRef) | |
} | |
if ref := getImagePullSecretReference(instance); ref != nil { | |
hiveDeployment.Spec.Template.Spec.ImagePullSecrets = append(hiveDeployment.Spec.Template.Spec.ImagePullSecrets, ref) | |
} |
pkg/operator/hive/hive.go
Outdated
hiveContainer.Env = append(hiveContainer.Env, hiveImagePullSecretEnvVar) | ||
} | ||
|
||
func (r *ReconcileHiveConfig) dynamicCopyHiveImagePullSecret(hLog log.FieldLogger, instance *hivev1.HiveConfig) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, yeah, let's clean this up.
For the getting, you should be able to use the existing controller-runtime-esque wrapper here. Example Get().
For the creating, you should be able to write a similar Create()
wrapper in that file.
The end result should be that you can make this func feel a lot more like it would if r
had/was a real c-r client.
pkg/operator/hive/operatorutils.go
Outdated
@@ -88,3 +90,41 @@ func applyDeploymentConfig(hiveConfig *hivev1.HiveConfig, deploymentName hivev1. | |||
container.Resources = *dc.Resources | |||
} | |||
} | |||
|
|||
func synchronizeUnstructuredSecrets(source, destination *unstructured.Unstructured) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and then all of this goes away.
@dlom: all tests passed! Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
xref: HIVE-2891
/assign @2uasimojo
/cc @huangmingxia
When deploying hive from a private image repository, in addition to supplying an
imagePullSecret
to the hive operator deployment, users will need to specify this same secret on theHiveConfig
. With this change, private image users will be able to provision clusters from any namespace, not just Hive's namespace