Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

support deploy klusterlet outside of managed cluster #172

Conversation

@zhujian7
Copy link
Member Author

zhujian7 commented Dec 16, 2021

@qiujian16 @zhiweiyin318 @xuezhaojun @ianzhang366 This PR Is ready for review.

but still need to:
- [ ] change the namespace from klusterlet name to {klusterlet name}-open-cluster-management-agent

  • add UT, integration tests

Copy link
Member

@qiujian16 qiujian16 left a comment

Choose a reason for hiding this comment

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

I might think it is a bit complicated with a lot of detachMode check in it.

My suggestion is we should separate the manifests and operations to

  1. those always put on managed cluster
  2. those always put on management cluster (it could be still managedcluster)
  3. those you have to check the mode

@@ -0,0 +1,13 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
Copy link
Member

Choose a reason for hiding this comment

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

why do we need to separated these. I think the manifests has only nuance with non-detached mode that you can render. Maintaining two lists of manifests would be hard since it is easy to update one and miss another

// KlusterletNamespace returns the klusterletNamespace to deploy the agents.
func KlusterletNamespace(mode operatorapiv1.InstallMode, klusterletName, specNamespace string) string {
if mode == operatorapiv1.InstallModeDetached {
// return fmt.Sprintf("%s-%s", klusterletName, KlusterletDefaultNamespace)
Copy link
Member

Choose a reason for hiding this comment

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

rm this line. Add more comment on this function

return klusterletName
}

if specNamespace == "" {
Copy link
Member

Choose a reason for hiding this comment

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

if len(specNamespace) == 0

it is safer

// resource status will be saved in the relatedResourcesStatuses, and will save the
// result to the klusterlet status if there is any error.
func (n *klusterletController) applyStaticFiles(ctx context.Context, klusterletName string,
staticFiles []string, relatedResourcesStatuses *[]operatorapiv1.RelatedResourceMeta,
Copy link
Member

Choose a reason for hiding this comment

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

return relatedResourcesStatuses rathe than adding a pointer

@@ -310,6 +320,24 @@ func (n *klusterletController) sync(ctx context.Context, controllerContext facto
return err
}

if detachedMode {
// In Deatched mode, apply role, rolebinding, service account for registration and work to the management cluster.
err = n.applyStaticFiles(ctx, klusterletName, detachedStaticResourceFiles, &relatedResources, &config, n.kubeClient,
Copy link
Member

Choose a reason for hiding this comment

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

why the apply static files is different from what you did on managed cluster

}

// syncSecret forked from resourceapply.SyncSecret, add an addition snippet to support sync secret to another cluster.
func syncSecret(client, targetClient coreclientv1.SecretsGetter, recorder events.Recorder,
Copy link
Member

Choose a reason for hiding this comment

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

put this in the helper. It is better to add ctx as the parameter

Copy link
Member Author

Choose a reason for hiding this comment

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

This func was put in the helper. and I'd prefer to add ctx after upgrading openshift/library-go to contain openshift/library-go#1121


if detachedMode {
Copy link
Member

Choose a reason for hiding this comment

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

this is confused..do we really need to apply any role/rolebinding in this ns?

Copy link
Member Author

Choose a reason for hiding this comment

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

need to create service account in this ns

controllerContext.Recorder(),
func(name string) ([]byte, error) {
template, err := manifests.Klusterlet111ManifestFiles.ReadFile(name)
template, err := manifests.KlusterletManifestFiles.ReadFile(name)
Copy link
Member

Choose a reason for hiding this comment

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

why change this line?

Copy link
Member Author

Choose a reason for hiding this comment

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

I put all klusterlet files in KlusterletManifestFiles to avoid duplication of code

Signed-off-by: zhujian <jiazhu@redhat.com>
Signed-off-by: zhujian <jiazhu@redhat.com>
Signed-off-by: zhujian <jiazhu@redhat.com>
Signed-off-by: zhujian <jiazhu@redhat.com>
@zhujian7 zhujian7 force-pushed the klusterlet-outside branch 2 times, most recently from 468d2ef to cec4ec8 Compare December 17, 2021 10:17
@zhiweiyin318
Copy link
Member

zhiweiyin318 commented Dec 17, 2021

do we need to add e2e cases for this scenario? like create 2 kind clusters in action and deploy with detach mode?
or add some integration tests?

@zhujian7
Copy link
Member Author

zhujian7 commented Dec 18, 2021

do we need to add e2e cases for this scenario? like create 2 kind clusters in action and deploy with detach mode? or add some integration tests?

Of course, this is what I am doing these days.

Signed-off-by: zhujian <jiazhu@redhat.com>
@zhujian7 zhujian7 force-pushed the klusterlet-outside branch 2 times, most recently from f103ad0 to 5922b9a Compare December 20, 2021 16:18
Signed-off-by: zhujian <jiazhu@redhat.com>
Signed-off-by: zhujian <jiazhu@redhat.com>
@zhujian7 zhujian7 force-pushed the klusterlet-outside branch 2 times, most recently from 80c0c21 to d2f4afd Compare December 21, 2021 08:09
Signed-off-by: zhujian <jiazhu@redhat.com>
@zhujian7
Copy link
Member Author

@qiujian16 all comments have been fixed, PTAL.
@zhiweiyin318 tests were added.

And the RBAC part needs a focused reviewing, please.

Copy link
Member

@qiujian16 qiujian16 left a comment

Choose a reason for hiding this comment

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

Thanks, I think it looks pretty neat. I still have some comments, but most of the can be done as a followup.

/approve

Makefile Outdated
@@ -38,14 +38,16 @@ operatorsdk_gen_dir:=$(dir $(OPERATOR_SDK))
OLM_NAMESPACE?=olm
OLM_VERSION?=0.16.1

KUSTOMIZE?=$(PERMANENT_TMP_GOPATH)/bin/kustomize
PWD=$(shell pwd)
Copy link
Member

Choose a reason for hiding this comment

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

I think we should update makefile in a followup PR.

return nil
}
if err != nil {
return err
}
klusterlet = klusterlet.DeepCopy()

detachedMode := klusterlet.Spec.DeployOption.Mode == operatorapiv1.InstallModeDetached
Copy link
Member

Choose a reason for hiding this comment

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

can we use eq in the template so we do not need to set this bool var?

ExternalManagedKubeConfigSecret: helpers.ExternalManagedKubeConfig,
ExternalManagedKubeConfigRegistrationSecret: helpers.ExternalManagedKubeConfigRegistration,
ExternalManagedKubeConfigWorkSecret: helpers.ExternalManagedKubeConfigWork,
DetachedMode: detachedMode,
Copy link
Member

Choose a reason for hiding this comment

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

InstallMode

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

if detachedMode {
managedClusterClients, err = n.buildManagedClusterClientsDetachedMode(n.kubeClient, config.KlusterletNamespace, config.ExternalManagedKubeConfigSecret)
if err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

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

Add a TODO here, you would need to set some status condition as the followup

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

if detachedMode {
// In detached mode, we should ensure the namespace on the managed cluster since
// some resources(eg:service account) are still deployed on managed cluster.
err := n.ensureNamespace(ctx, managedClusterClients.kubeClient, klusterletName, config.KlusterletNamespace)
Copy link
Member

Choose a reason for hiding this comment

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

should we still need this? OR why we only need to ensure this on detached mode?

Copy link
Member Author

@zhujian7 zhujian7 Dec 22, 2021

Choose a reason for hiding this comment

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

why we only need to ensure this on detached mode?

In detached mode, the managed cluster and management cluster are separated, the namespace in the management cluster has been ensured previously.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Dec 22, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qiujian16, zhujian7

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Signed-off-by: zhujian <jiazhu@redhat.com>
… cluster

Signed-off-by: zhujian <jiazhu@redhat.com>
@zhujian7
Copy link
Member Author

@qiujian16 all comments have been fixed, and I add another commit(last commit of this PR) to distinguish the RBAC resource names of managed cluster and management cluster, the RBAC resources names are not in conflict now but may conflict in the future, I think it is necessary to separate. PTAL. Thanks.

@zhujian7
Copy link
Member Author

/hold

@zhujian7
Copy link
Member Author

/hold cancel

"kind": "Klusterlet",
"metadata": {
"name": "klusterlet"
},
Copy link
Member

Choose a reason for hiding this comment

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

do not need detached klusterlet in alm-examples. this example user can apply directly on operatorhub. so we cannot put 2 klusterlet here.

@zhujian7 zhujian7 force-pushed the klusterlet-outside branch 2 times, most recently from 66c0784 to c307e35 Compare December 24, 2021 03:52
@zhujian7
Copy link
Member Author

The makefile and README.md will be updated at a follow-up PR.

@zhujian7 zhujian7 force-pushed the klusterlet-outside branch 2 times, most recently from 88a626d to 73cf438 Compare December 24, 2021 10:11
Signed-off-by: zhujian <jiazhu@redhat.com>
Signed-off-by: zhujian <jiazhu@redhat.com>
@zhujian7
Copy link
Member Author

@zhiweiyin318 csv updated. PTAL.

@zhiweiyin318
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Jan 4, 2022
@openshift-merge-robot openshift-merge-robot merged commit dcf93fa into open-cluster-management-io:main Jan 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants