Skip to content

Commit

Permalink
🐛 correct the agent deployment name in different install mode (#265)
Browse files Browse the repository at this point in the history
Signed-off-by: Yang Le <[email protected]>
  • Loading branch information
elgnay authored Sep 5, 2023
1 parent 31f9059 commit 7adf6ee
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ func (k *bootstrapController) sync(ctx context.Context, controllerContext factor
func (k *bootstrapController) processRebootstrap(ctx context.Context, agentNamespace string, klusterlet *operatorapiv1.Klusterlet,
recorder events.Recorder, requeueFunc func(time.Duration)) error {
deploymentName := fmt.Sprintf("%s-registration-agent", klusterlet.Name)
if helpers.IsSingleton(klusterlet.Spec.DeployOption.Mode) {
deploymentName = fmt.Sprintf("%s-agent", klusterlet.Name)
}
deployment, err := k.kubeClient.AppsV1().Deployments(agentNamespace).Get(ctx, deploymentName, metav1.GetOptions{})
if errors.IsNotFound(err) {
return k.completeRebootstrap(ctx, agentNamespace, klusterlet, recorder)
Expand All @@ -194,7 +197,7 @@ func (k *bootstrapController) processRebootstrap(ctx context.Context, agentNames
return k.completeRebootstrap(ctx, agentNamespace, klusterlet, recorder)
}

// there still is registation agent pod running. Resync in 5 seconds
// there still is agent pod running. Resync in 5 seconds
requeueFunc(5 * time.Second)
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestSync(t *testing.T) {
cases := []struct {
name string
queueKey string
klusterletInstallMode operatorapiv1.InstallMode
initRebootstrapping bool
objects []runtime.Object
expectedRebootstrapping bool
Expand Down Expand Up @@ -119,13 +120,14 @@ func TestSync(t *testing.T) {
},
},
{
name: "wait for scaling down",
queueKey: "test/test",
initRebootstrapping: true,
name: "wait for scaling down",
queueKey: "test/test",
klusterletInstallMode: operatorapiv1.InstallModeSingleton,
initRebootstrapping: true,
objects: []runtime.Object{
newSecret("bootstrap-hub-kubeconfig", "test", newKubeConfig("https://10.0.118.48:6443", "")),
newHubKubeConfigSecret("test", time.Now().Add(60*time.Second).UTC()),
newDeploymentWithAvailableReplicas("test-registration-agent", "test", 1),
newDeploymentWithAvailableReplicas("test-agent", "test", 1),
},
expectedRebootstrapping: true,
validateActions: func(t *testing.T, actions []clienttesting.Action) {
Expand All @@ -150,7 +152,7 @@ func TestSync(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
fakeKubeClient := fakekube.NewSimpleClientset(c.objects...)
klusterlet := newKlusterlet("test", "test")
klusterlet := newKlusterlet("test", "test", c.klusterletInstallMode)
if c.initRebootstrapping {
klusterlet.Status.Conditions = []metav1.Condition{
{
Expand Down Expand Up @@ -241,19 +243,19 @@ func TestBootstrapSecretQueueKeyFunc(t *testing.T) {
{
name: "key by bootstrap secret",
object: newSecret("bootstrap-hub-kubeconfig", "test", []byte{}),
klusterlet: newKlusterlet("testklusterlet", "test"),
klusterlet: newKlusterlet("testklusterlet", "test", ""),
expectedKey: []string{"test/testklusterlet"},
},
{
name: "key by wrong secret",
object: newSecret("dummy", "test", []byte{}),
klusterlet: newKlusterlet("testklusterlet", "test"),
klusterlet: newKlusterlet("testklusterlet", "test", ""),
expectedKey: []string{},
},
{
name: "key by klusterlet with empty namespace",
object: newSecret("bootstrap-hub-kubeconfig", "open-cluster-management-agent", []byte{}),
klusterlet: newKlusterlet("testklusterlet", ""),
klusterlet: newKlusterlet("testklusterlet", "", ""),
expectedKey: []string{"open-cluster-management-agent/testklusterlet"},
},
}
Expand All @@ -275,13 +277,16 @@ func TestBootstrapSecretQueueKeyFunc(t *testing.T) {
}
}

func newKlusterlet(name, namespace string) *operatorapiv1.Klusterlet {
func newKlusterlet(name, namespace string, installMode operatorapiv1.InstallMode) *operatorapiv1.Klusterlet {
return &operatorapiv1.Klusterlet{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: operatorapiv1.KlusterletSpec{
Namespace: namespace,
DeployOption: operatorapiv1.KlusterletDeployOption{
Mode: installMode,
},
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ func (r *runtimeReconcile) reconcile(ctx context.Context, klusterlet *operatorap

func (r *runtimeReconcile) installSingletonAgent(ctx context.Context, klusterlet *operatorapiv1.Klusterlet,
config klusterletConfig) (*operatorapiv1.Klusterlet, reconcileState, error) {
// Check if the klusterlet is in rebootstrapping state.
// The agent is scaled to 0 if the klusterlet is in rebootstrapping state.
runtimeConfig := config
if meta.IsStatusConditionTrue(klusterlet.Status.Conditions, helpers.KlusterletRebootstrapProgressing) {
runtimeConfig.Replica = 0
}

// Deploy singleton agent
_, generationStatus, err := helpers.ApplyDeployment(
ctx,
Expand All @@ -162,7 +169,7 @@ func (r *runtimeReconcile) installSingletonAgent(ctx context.Context, klusterlet
if err != nil {
return nil, err
}
objData := assets.MustCreateAssetFromTemplate(name, template, config).Data
objData := assets.MustCreateAssetFromTemplate(name, template, runtimeConfig).Data
helpers.SetRelatedResourcesStatusesWithObj(&klusterlet.Status.RelatedResources, objData)
return objData, nil
},
Expand Down

0 comments on commit 7adf6ee

Please sign in to comment.