Skip to content

Commit

Permalink
Remove install mode detached (open-cluster-management-io#282)
Browse files Browse the repository at this point in the history
Signed-off-by: zhujian <jiazhu@redhat.com>

Signed-off-by: zhujian <jiazhu@redhat.com>
  • Loading branch information
zhujian7 authored Oct 17, 2022
1 parent 8745a76 commit 432fac3
Show file tree
Hide file tree
Showing 10 changed files with 7 additions and 148 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ apply-spoke-cr: bootstrap-secret
| $(KUBECTL) apply -f -

apply-spoke-cr-hosted: bootstrap-secret-hosted external-managed-secret
$(KUSTOMIZE) build deploy/klusterlet/config/samples | $(SED_CMD) -e "s,mode: Default,mode: Detached," -e "s,quay.io/open-cluster-management/registration,$(REGISTRATION_IMAGE)," -e "s,quay.io/open-cluster-management/work,$(WORK_IMAGE)," -e "s,cluster1,$(MANAGED_CLUSTER_NAME)," | $(KUBECTL) apply -f -
$(KUSTOMIZE) build deploy/klusterlet/config/samples | $(SED_CMD) -e "s,mode: Default,mode: Hosted," -e "s,quay.io/open-cluster-management/registration,$(REGISTRATION_IMAGE)," -e "s,quay.io/open-cluster-management/work,$(WORK_IMAGE)," -e "s,cluster1,$(MANAGED_CLUSTER_NAME)," | $(KUBECTL) apply -f -

clean-hub-cr:
$(KUBECTL) delete managedcluster --all --ignore-not-found
Expand Down
4 changes: 2 additions & 2 deletions pkg/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ func LoadClientConfigFromSecret(secret *corev1.Secret) (*rest.Config, error) {
func DetermineReplica(ctx context.Context, kubeClient kubernetes.Interface, mode operatorapiv1.InstallMode, kubeVersion *version.Version) int32 {
// For hosted mode, there may be many cluster-manager/klusterlet running on the management cluster,
// set the replica to 1 to reduce the footprint of the management cluster.
if mode == operatorapiv1.InstallModeDetached || mode == operatorapiv1.InstallModeHosted {
if mode == operatorapiv1.InstallModeHosted {
return singleReplica
}

Expand Down Expand Up @@ -774,7 +774,7 @@ func KlusterletNamespace(klusterlet *operatorapiv1.Klusterlet) string {
// AgentNamespace returns the namespace to deploy the agents.
// It is on the managed cluster in the Default mode, and on the management cluster in the Hosted mode.
func AgentNamespace(klusterlet *operatorapiv1.Klusterlet) string {
if klusterlet.Spec.DeployOption.Mode == operatorapiv1.InstallModeDetached || klusterlet.Spec.DeployOption.Mode == operatorapiv1.InstallModeHosted {
if klusterlet.Spec.DeployOption.Mode == operatorapiv1.InstallModeHosted {
return klusterlet.GetName()
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/helpers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1613,15 +1613,15 @@ func TestGetHubKubeconfig(t *testing.T) {
expectedErr: false,
},
{
name: "detach mode no secret",
name: "hosted mode no secret",
mode: operatorapiv1.InstallModeHosted,
secret: []runtime.Object{},
namespace: "test",
expectedHost: "localhost",
expectedErr: true,
},
{
name: "detach mode",
name: "hosted mode",
mode: operatorapiv1.InstallModeHosted,
secret: []runtime.Object{newKubeConfigSecret("test", ExternalHubKubeConfig, newKubeConfig("testhost", "tls.crt", "tls.key"), []byte("--- TRUNCATED ---"), []byte("--- REDACTED ---"))},
namespace: "test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,6 @@ func (n *klusterletCleanupController) sync(ctx context.Context, controllerContex
klusterlet = klusterlet.DeepCopy()
installMode := klusterlet.Spec.DeployOption.Mode

// TODO: remove this when detached mode is not used in klusterlet
if installMode == operatorapiv1.InstallModeDetached {
installMode = operatorapiv1.InstallModeHosted
}

if klusterlet.DeletionTimestamp.IsZero() {
if !hasFinalizer(klusterlet, klusterletFinalizer) {
return n.addFinalizer(ctx, klusterlet, klusterletFinalizer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,6 @@ func (n *klusterletController) sync(ctx context.Context, controllerContext facto
}
}

// TODO: remove this when detached mode is not used in klusterlet
if config.InstallMode == operatorapiv1.InstallModeDetached {
config.InstallMode = operatorapiv1.InstallModeHosted
}

if config.InstallMode == operatorapiv1.InstallModeHosted {
managedClusterClients, err = n.buildManagedClusterClientsHostedMode(ctx,
n.kubeClient, config.AgentNamespace, config.ExternalManagedKubeConfigSecret)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func assertWorkDeployment(t *testing.T, actions []clienttesting.Action, verb, cl
"--hub-kubeconfig=/spoke/hub-kubeconfig/kubeconfig",
}

if mode == operatorapiv1.InstallModeDetached || mode == operatorapiv1.InstallModeHosted {
if mode == operatorapiv1.InstallModeHosted {
expectArgs = append(expectArgs, "--spoke-kubeconfig=/spoke/config/kubeconfig")
}

Expand Down
42 changes: 0 additions & 42 deletions test/e2e/addon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,48 +65,6 @@ var _ = Describe("Manage the managed cluster addons", func() {
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
})

// TODO: remove this after the detached mode is not used in klusterlet
It("Create one managed cluster addon and make sure it is available in Detached mode", func() {
var err error
By(fmt.Sprintf("create klusterlet %v with managed cluster name %v", klusterletName, clusterName))
_, err = t.CreateKlusterlet(klusterletName, clusterName, agentNamespace, operatorapiv1.InstallModeDetached)
Expect(err).ToNot(HaveOccurred())

By(fmt.Sprintf("waiting for the managed cluster %v to be created", clusterName))
Eventually(func() error {
_, err = t.GetCreatedManagedCluster(clusterName)
return err
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())

By(fmt.Sprintf("approve the created managed cluster %v", clusterName))
Eventually(func() error {
return t.ApproveCSR(clusterName)
}, t.EventuallyTimeout, t.EventuallyInterval).Should(Succeed())

By(fmt.Sprintf("accept the created managed cluster %v", clusterName))
Eventually(func() error {
return t.AcceptsClient(clusterName)
}, t.EventuallyTimeout, t.EventuallyInterval).Should(Succeed())

By(fmt.Sprintf("waiting for the managed cluster %v to be ready", clusterName))
Eventually(func() error {
return t.CheckManagedClusterStatus(clusterName)
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())

By(fmt.Sprintf("create the addon %v on the managed cluster namespace %v", addOnName, clusterName))
err = t.CreateManagedClusterAddOn(clusterName, addOnName)
Expect(err).ToNot(HaveOccurred())

By(fmt.Sprintf("create the addon lease %v on addon install namespace %v", addOnName, addOnName))
err = t.CreateManagedClusterAddOnLease(addOnName, addOnName)
Expect(err).ToNot(HaveOccurred())

By(fmt.Sprintf("wait the addon %v available condition to be true", addOnName))
Eventually(func() error {
return t.CheckManagedClusterAddOnStatus(clusterName, addOnName)
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
})

It("Create one managed cluster addon and make sure it is available in Hosted mode", func() {
var err error
By(fmt.Sprintf("create klusterlet %v with managed cluster name %v", klusterletName, clusterName))
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (t *Tester) CreateKlusterlet(name, clusterName, klusterletNamespace string,
}
}

if mode == operatorapiv1.InstallModeDetached || mode == operatorapiv1.InstallModeHosted {
if mode == operatorapiv1.InstallModeHosted {
// create external-managed-kubeconfig, will use the same cluster to simulate the Hosted mode.
secret.Namespace = agentNamespace
secret.Name = helpers.ExternalManagedKubeConfig
Expand Down
40 changes: 0 additions & 40 deletions test/e2e/klusterlet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,46 +151,6 @@ var _ = Describe("Create klusterlet CR", func() {
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
})

// TODO: remove this after the detached mode is not used in klusterlet
It("Create klusterlet CR in Detached mode", func() {
By(fmt.Sprintf("create klusterlet %v with managed cluster name %v", klusterletName, clusterName))
_, err := t.CreateKlusterlet(klusterletName, clusterName, klusterletNamespace, operatorapiv1.InstallModeDetached)
Expect(err).ToNot(HaveOccurred())

By(fmt.Sprintf("waiting for the managed cluster %v to be created", clusterName))
Eventually(func() error {
_, err := t.GetCreatedManagedCluster(clusterName)
return err
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())

By(fmt.Sprintf("check klusterlet %s status", klusterletName))
Eventually(func() error {
err := t.checkKlusterletStatus(klusterletName, "HubConnectionDegraded", "BootstrapSecretFunctional,HubKubeConfigSecretMissing", metav1.ConditionTrue)
return err
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())

By(fmt.Sprintf("approve the created managed cluster %v", clusterName))
Eventually(func() error {
return t.ApproveCSR(clusterName)
}, t.EventuallyTimeout, t.EventuallyInterval).Should(Succeed())

By(fmt.Sprintf("accept the created managed cluster %v", clusterName))
Eventually(func() error {
return t.AcceptsClient(clusterName)
}, t.EventuallyTimeout, t.EventuallyInterval).Should(Succeed())

By(fmt.Sprintf("waiting for the managed cluster %v to be ready", clusterName))
Eventually(func() error {
return t.CheckManagedClusterStatus(clusterName)
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())

By(fmt.Sprintf("check klusterlet %s status", klusterletName))
Eventually(func() error {
err := t.checkKlusterletStatus(klusterletName, "HubConnectionDegraded", "HubConnectionFunctional", metav1.ConditionFalse)
return err
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
})

It("Create klusterlet CR in Hosted mode", func() {
By(fmt.Sprintf("create klusterlet %v with managed cluster name %v", klusterletName, clusterName))
_, err := t.CreateKlusterlet(klusterletName, clusterName, klusterletNamespace, operatorapiv1.InstallModeHosted)
Expand Down
49 changes: 0 additions & 49 deletions test/e2e/work_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,55 +78,6 @@ var _ = Describe("Create klusterlet and then create a configmap by manifestwork"
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(BeTrue())
})

// TODO: remove this after the detached mode is not used in klusterlet
It("Create configmap using manifestwork and then delete klusterlet in Detached mode", func() {
var err error
By(fmt.Sprintf("create klusterlet %v with managed cluster name %v", klusterletName, clusterName))
_, err = t.CreateKlusterlet(klusterletName, clusterName, agentNamespace, operatorapiv1.InstallModeDetached)
Expect(err).ToNot(HaveOccurred())

By(fmt.Sprintf("waiting for the managed cluster %v to be created", clusterName))
Eventually(func() error {
_, err = t.GetCreatedManagedCluster(clusterName)
return err
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())

By(fmt.Sprintf("approve the created managed cluster %v", clusterName))
Eventually(func() error {
return t.ApproveCSR(clusterName)
}, t.EventuallyTimeout, t.EventuallyInterval).Should(Succeed())

By(fmt.Sprintf("accept the created managed cluster %v", clusterName))
Eventually(func() error {
return t.AcceptsClient(clusterName)
}, t.EventuallyTimeout, t.EventuallyInterval).Should(Succeed())

By(fmt.Sprintf("waiting for the managed cluster %v to be ready", clusterName))
Eventually(func() error {
return t.CheckManagedClusterStatus(clusterName)
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())

By(fmt.Sprintf("create configmap %v/%v using manifestwork %v/%v", configMapNamespace,
configMapName, clusterName, workName))
_, err = t.CreateWorkOfConfigMap(workName, clusterName, configMapName, configMapNamespace)
Expect(err).ToNot(HaveOccurred())

By(fmt.Sprintf("waiting for configmap %v/%v to be created", configMapNamespace, configMapName))
Eventually(func() error {
_, err := t.KubeClient.CoreV1().ConfigMaps(configMapNamespace).
Get(context.TODO(), configMapName, metav1.GetOptions{})
return err
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())

By(fmt.Sprintf("delete manifestwork %v/%v", clusterName, workName))
err = t.WorkClient.WorkV1().ManifestWorks(clusterName).Delete(context.Background(), workName, metav1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred())
Eventually(func() bool {
_, err := t.WorkClient.WorkV1().ManifestWorks(clusterName).Get(context.Background(), workName, metav1.GetOptions{})
return errors.IsNotFound(err)
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(BeTrue())
})

It("Create configmap using manifestwork and then delete klusterlet in Hosted mode", func() {
var err error
By(fmt.Sprintf("create klusterlet %v with managed cluster name %v", klusterletName, clusterName))
Expand Down

0 comments on commit 432fac3

Please sign in to comment.