Skip to content

Commit c0abce8

Browse files
author
Arvind Thirumurugan
committed
minor refactor
Signed-off-by: Arvind Thirumurugan <arvindth@microsoft.com>
1 parent a9c1e56 commit c0abce8

3 files changed

Lines changed: 14 additions & 21 deletions

File tree

cmd/crdinstaller/utils/util.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import (
2424
)
2525

2626
const (
27-
// ArcInstallationKey is the key used to indicate if the installation is for ARC AKS cluster.
28-
ArcInstallationKey = "crd-installer.azurefleet.io/arc"
2927
// CRDInstallerLabelKey is the label key used to indicate that a CRD is managed by the installer.
3028
CRDInstallerLabelKey = "crd-installer.azurefleet.io/managed"
3129
// AzureManagedLabelKey is the label key used to indicate that a CRD is managed by an azure resource.
@@ -44,7 +42,7 @@ const (
4442
ModeHub = "hub"
4543
// ModeMember installs member cluster CRDs.
4644
ModeMember = "member"
47-
// ModeArcMember installs member cluster CRDs with ARC labels.
45+
// ModeArcMember installs member cluster CRDs with ARC member label value.
4846
ModeArcMember = "arcMember"
4947
)
5048

@@ -75,16 +73,17 @@ func InstallCRD(ctx context.Context, client client.Client, crd *apiextensionsv1.
7573
if existingCRD.Labels == nil {
7674
existingCRD.Labels = make(map[string]string)
7775
}
78-
if mode == ModeArcMember {
79-
// For ARC AKS installation, we want to add an additional label to indicate this is an ARC managed cluster,
80-
// needed for clean up of CRD by kube-addon-manager.
81-
existingCRD.Labels[ArcInstallationKey] = trueLabelValue
82-
}
8376
// Ensure the label for management by the installer is set.
8477
existingCRD.Labels[CRDInstallerLabelKey] = trueLabelValue
8578
// Also set the Azure managed label to indicate this is managed by Fleet,
8679
// needed for clean up of CRD by kube-addon-manager.
87-
existingCRD.Labels[AzureManagedLabelKey] = FleetLabelValue
80+
if mode == ModeArcMember {
81+
// For aks ARC, we set the label value to "arcMember" to avoid clean up of CRDs by OM.
82+
existingCRD.Labels[AzureManagedLabelKey] = ModeArcMember
83+
} else {
84+
existingCRD.Labels[AzureManagedLabelKey] = FleetLabelValue
85+
}
86+
8887
return nil
8988
}
9089
err := install(ctx, client, &existingCRD, mutFn)

cmd/crdinstaller/utils/util_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,13 @@ func TestInstallCRD(t *testing.T) {
202202
t.Errorf("Expected CRD label %s to be 'true', got %q", CRDInstallerLabelKey, installedCRD.Labels[CRDInstallerLabelKey])
203203
}
204204

205-
if installedCRD.Labels[AzureManagedLabelKey] != FleetLabelValue {
206-
t.Errorf("Expected CRD label %s to be %q, got %q", AzureManagedLabelKey, FleetLabelValue, installedCRD.Labels[AzureManagedLabelKey])
207-
}
208-
209205
if tt.mode == ModeArcMember {
210-
if installedCRD.Labels[ArcInstallationKey] != "true" {
211-
t.Errorf("Expected CRD label %s to be 'true', got %q", ArcInstallationKey, installedCRD.Labels[ArcInstallationKey])
206+
if installedCRD.Labels[AzureManagedLabelKey] != ModeArcMember {
207+
t.Errorf("Expected CRD label %s to be %q, got %q", AzureManagedLabelKey, ModeArcMember, installedCRD.Labels[AzureManagedLabelKey])
212208
}
213209
} else {
214-
if _, exists := installedCRD.Labels[ArcInstallationKey]; exists {
215-
t.Errorf("Expected CRD label %s to not exist for non-ARC installation", ArcInstallationKey)
210+
if installedCRD.Labels[AzureManagedLabelKey] != FleetLabelValue {
211+
t.Errorf("Expected CRD label %s to be %q, got %q", AzureManagedLabelKey, FleetLabelValue, installedCRD.Labels[AzureManagedLabelKey])
216212
}
217213
}
218214

test/crdinstaller/crd_installer_integration_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ var _ = Describe("Test CRD Installer, Create and Update CRD", Ordered, func() {
106106
It("should verify CRD has ARC installation label", func() {
107107
ensureCRDExistsWithLabels(map[string]string{
108108
cmdCRDInstaller.CRDInstallerLabelKey: "true",
109-
cmdCRDInstaller.AzureManagedLabelKey: cmdCRDInstaller.FleetLabelValue,
110-
cmdCRDInstaller.ArcInstallationKey: "true",
109+
cmdCRDInstaller.AzureManagedLabelKey: cmdCRDInstaller.ModeArcMember,
111110
})
112111
crd := &apiextensionsv1.CustomResourceDefinition{}
113112
Expect(k8sClient.Get(ctx, types.NamespacedName{Name: crdName}, crd)).NotTo(HaveOccurred(), "CRD %s should be installed", crdName)
@@ -133,8 +132,7 @@ var _ = Describe("Test CRD Installer, Create and Update CRD", Ordered, func() {
133132
ensureCRDExistsWithLabels(map[string]string{
134133
randomLabelKey: "true",
135134
cmdCRDInstaller.CRDInstallerLabelKey: "true",
136-
cmdCRDInstaller.AzureManagedLabelKey: cmdCRDInstaller.FleetLabelValue,
137-
cmdCRDInstaller.ArcInstallationKey: "true",
135+
cmdCRDInstaller.AzureManagedLabelKey: cmdCRDInstaller.ModeArcMember,
138136
})
139137
crd := &apiextensionsv1.CustomResourceDefinition{}
140138
Expect(k8sClient.Get(ctx, types.NamespacedName{Name: crdName}, crd)).NotTo(HaveOccurred(), "CRD %s should be installed", crdName)

0 commit comments

Comments
 (0)