diff --git a/config/crds/hive_v1alpha1_clusterdeployment.yaml b/config/crds/hive_v1alpha1_clusterdeployment.yaml index 18b85ce09a1..3aceb4a2c38 100644 --- a/config/crds/hive_v1alpha1_clusterdeployment.yaml +++ b/config/crds/hive_v1alpha1_clusterdeployment.yaml @@ -488,8 +488,9 @@ spec: description: APIURL is the URL where the cluster's API can be accessed. type: string clusterID: - description: ClusterID is a unique identifier for this cluster generated - during installation. + description: ClusterID is a globally unique identifier for this cluster + generated during installation. Used for reporting metrics among other + places. type: string clusterVersionStatus: description: ClusterVersionStatus will hold a copy of the remote cluster's @@ -513,9 +514,6 @@ spec: the update version. When this field is part of spec, version is optional if payload is specified. type: string - required: - - version - - payload type: object type: array conditions: @@ -572,9 +570,6 @@ spec: update version. When this field is part of spec, version is optional if payload is specified. type: string - required: - - version - - payload type: object generation: description: generation reports which version of the spec is being @@ -627,7 +622,6 @@ spec: - state - startedTime - completionTime - - version - payload type: object type: array @@ -652,6 +646,10 @@ spec: description: FederatedClusterRef is the reference to the federated cluster resource associated with this ClusterDeployment. type: object + infraID: + description: InfraID is an identifier for this cluster generated during + installation and used for tagging/naming resources in cloud providers. + type: string installed: description: Installed is true if the installer job has successfully completed for this cluster. diff --git a/contrib/pkg/installmanager/installmanager.go b/contrib/pkg/installmanager/installmanager.go index f336336aba2..9baa9f0e67e 100644 --- a/contrib/pkg/installmanager/installmanager.go +++ b/contrib/pkg/installmanager/installmanager.go @@ -274,12 +274,13 @@ func (m *InstallManager) cleanupBeforeInstall(cd *hivev1.ClusterDeployment) erro return err } - if cd.Status.ClusterID != "" { - if err := m.runUninstaller(m.ClusterName, m.Region, cd.Status.ClusterID, m.log); err != nil { + if cd.Status.InfraID != "" { + if err := m.runUninstaller(m.ClusterName, m.Region, cd.Status.InfraID, m.log); err != nil { return err } - // Cleanup successful, we must now clear the UUID from status: + // Cleanup successful, we must now clear the clusterID and infraID from status: cd.Status.ClusterID = "" + cd.Status.InfraID = "" if err := m.DynamicClient.Status().Update(context.Background(), cd); err != nil { // This will cause a job re-try, which is fine as we'll just try to cleanup and // find nothing. @@ -318,10 +319,10 @@ func (m *InstallManager) cleanupTerraformFiles() error { return nil } -func runUninstaller(clusterName, region, clusterID string, logger log.FieldLogger) error { +func runUninstaller(clusterName, region, infraID string, logger log.FieldLogger) error { // run the uninstaller to clean up any cloud resources previously created filters := []aws.Filter{ - {kubernetesKeyPrefix + clusterID: "owned"}, + {kubernetesKeyPrefix + infraID: "owned"}, } uninstaller := &aws.ClusterUninstaller{ Filters: filters, @@ -416,10 +417,11 @@ func uploadClusterMetadata(cd *hivev1.ClusterDeployment, m *InstallManager) erro return err } - cd.Status.ClusterID = md.InfraID - if cd.Status.ClusterID == "" { - m.log.Error("cluster metadata did not contain clusterID") - return fmt.Errorf("cluster metadata did not contain clusterID") + cd.Status.ClusterID = md.ClusterID + cd.Status.InfraID = md.InfraID + if cd.Status.InfraID == "" { + m.log.Error("cluster metadata did not contain infraID") + return fmt.Errorf("cluster metadata did not contain infraID") } controllerutils.FixupEmptyClusterVersionFields(&cd.Status.ClusterVersionStatus) diff --git a/contrib/pkg/installmanager/installmanager_test.go b/contrib/pkg/installmanager/installmanager_test.go index dffc8d80ed5..4bf774eb2a0 100644 --- a/contrib/pkg/installmanager/installmanager_test.go +++ b/contrib/pkg/installmanager/installmanager_test.go @@ -43,7 +43,9 @@ const ( testClusterName = "test-cluster" testNamespace = "test-namespace" // testClusterID matches the json blob below: - testClusterID = "test-cluster-fe9531" + testClusterID = "fe953108-f64c-4166-bb8e-20da7665ba00" + // testInfraID matches the json blob below: + testInfraID = "test-cluster-fe9531" installerBinary = "openshift-install" fakeInstallerBinary = `#!/bin/sh diff --git a/pkg/apis/hive/v1alpha1/clusterdeployment_types.go b/pkg/apis/hive/v1alpha1/clusterdeployment_types.go index 33ae7360e6e..bd4ac41ff7a 100644 --- a/pkg/apis/hive/v1alpha1/clusterdeployment_types.go +++ b/pkg/apis/hive/v1alpha1/clusterdeployment_types.go @@ -114,9 +114,12 @@ type AWSPlatformSecrets struct { // ClusterDeploymentStatus defines the observed state of ClusterDeployment type ClusterDeploymentStatus struct { - // ClusterID is a unique identifier for this cluster generated during installation. + // ClusterID is a globally unique identifier for this cluster generated during installation. Used for reporting metrics among other places. ClusterID string `json:"clusterID,omitempty"` + // InfraID is an identifier for this cluster generated during installation and used for tagging/naming resources in cloud providers. + InfraID string `json:"infraID,omitempty"` + // Installed is true if the installer job has successfully completed for this cluster. Installed bool `json:"installed"` diff --git a/pkg/controller/clusterdeployment/clusterdeployment_controller.go b/pkg/controller/clusterdeployment/clusterdeployment_controller.go index 746666a3bcb..dd214e13115 100644 --- a/pkg/controller/clusterdeployment/clusterdeployment_controller.go +++ b/pkg/controller/clusterdeployment/clusterdeployment_controller.go @@ -475,8 +475,8 @@ func (r *ReconcileClusterDeployment) syncDeletedClusterDeployment(cd *hivev1.Clu return reconcile.Result{}, nil } - if cd.Status.ClusterID == "" { - cdLog.Warn("skipping uninstall for cluster that never had clusterID set") + if cd.Status.InfraID == "" { + cdLog.Warn("skipping uninstall for cluster that never had infraID set") err = r.removeClusterDeploymentFinalizer(cd) if err != nil { cdLog.WithError(err).Error("error removing finalizer") diff --git a/pkg/controller/clusterdeployment/clusterdeployment_controller_test.go b/pkg/controller/clusterdeployment/clusterdeployment_controller_test.go index 285369b8174..96eb2a6092d 100644 --- a/pkg/controller/clusterdeployment/clusterdeployment_controller_test.go +++ b/pkg/controller/clusterdeployment/clusterdeployment_controller_test.go @@ -49,6 +49,7 @@ const ( testName = "foo-lqmsh" testClusterName = "bar" testClusterID = "testFooClusterUUID" + testInfraID = "testFooInfraID" installJobName = "foo-lqmsh-install" uninstallJobName = "foo-lqmsh-uninstall" testNamespace = "default" @@ -416,6 +417,7 @@ func testClusterDeployment() *hivev1.ClusterDeployment { }, Status: hivev1.ClusterDeploymentStatus{ ClusterID: testClusterID, + InfraID: testInfraID, }, } controllerutils.FixupEmptyClusterVersionFields(&cd.Status.ClusterVersionStatus) diff --git a/pkg/controller/federation/clusterdeployment_federation_controller_test.go b/pkg/controller/federation/clusterdeployment_federation_controller_test.go index 7c49c17ea2b..af3a5485155 100644 --- a/pkg/controller/federation/clusterdeployment_federation_controller_test.go +++ b/pkg/controller/federation/clusterdeployment_federation_controller_test.go @@ -222,6 +222,7 @@ func testClusterDeployment() *hivev1.ClusterDeployment { }, Status: hivev1.ClusterDeploymentStatus{ ClusterID: "cluster-id", + InfraID: "infra-id", }, } controllerutils.FixupEmptyClusterVersionFields(&cd.Status.ClusterVersionStatus) diff --git a/pkg/controller/remotemachineset/remotemachineset_controller.go b/pkg/controller/remotemachineset/remotemachineset_controller.go index 89711089394..c1e88857e36 100644 --- a/pkg/controller/remotemachineset/remotemachineset_controller.go +++ b/pkg/controller/remotemachineset/remotemachineset_controller.go @@ -308,7 +308,7 @@ func (r *ReconcileRemoteMachineSet) generateMachineSetsFromClusterDeployment(cd workerPool.Platform.AWS.Zones = azs } - icMachineSets, err := installaws.MachineSets(cd.Status.ClusterID, ic, &workerPool, defaultAMI, workerPool.Name, "worker-user-data") + icMachineSets, err := installaws.MachineSets(cd.Status.InfraID, ic, &workerPool, defaultAMI, workerPool.Name, "worker-user-data") if err != nil { return nil, err } diff --git a/pkg/controller/remotemachineset/remotemachineset_controller_test.go b/pkg/controller/remotemachineset/remotemachineset_controller_test.go index 1f5219eb075..18c5ff817c8 100644 --- a/pkg/controller/remotemachineset/remotemachineset_controller_test.go +++ b/pkg/controller/remotemachineset/remotemachineset_controller_test.go @@ -50,7 +50,8 @@ import ( const ( testName = "foo" testNamespace = "default" - testClusterID = "foo-12345" + testClusterID = "foo-12345-uuid" + testInfraID = "foo-12345" machineAPINamespace = "openshift-machine-api" metadataName = "foo-metadata" adminKubeconfigSecret = "foo-admin-kubeconfig" @@ -420,7 +421,7 @@ func testMachineSet(name string, machineType string, unstompedAnnotation bool, r Namespace: machineAPINamespace, Labels: map[string]string{ "sigs.k8s.io/cluster-api-machine-type": machineType, - "sigs.k8s.io/cluster-api-cluster": testClusterID, + "sigs.k8s.io/cluster-api-cluster": testInfraID, "sigs.k8s.io/cluster-api-machine-role": machineType, }, Generation: int64(generation), @@ -479,6 +480,7 @@ func testClusterDeployment(computePools []hivev1.MachinePool) *hivev1.ClusterDep Installed: true, AdminKubeconfigSecret: corev1.LocalObjectReference{Name: fmt.Sprintf("%s-admin-kubeconfig", testName)}, ClusterID: testClusterID, + InfraID: testInfraID, }, } } diff --git a/pkg/install/convertconfig_test.go b/pkg/install/convertconfig_test.go index c9db2a4b02c..cc5472fa0c2 100644 --- a/pkg/install/convertconfig_test.go +++ b/pkg/install/convertconfig_test.go @@ -41,7 +41,6 @@ func init() { const ( testName = "foo" testNamespace = "default" - testClusterID = "foo" testAMI = "ami-totallyfake" adminPassword = "adminpassword" adminSSHKey = "adminSSH" diff --git a/pkg/install/generate.go b/pkg/install/generate.go index 9a778db17f6..53a43ff25b5 100644 --- a/pkg/install/generate.go +++ b/pkg/install/generate.go @@ -344,7 +344,7 @@ func GenerateUninstallerJob( "debug", "--region", cd.Spec.AWS.Region, - fmt.Sprintf("kubernetes.io/cluster/%s=owned", cd.Status.ClusterID), + fmt.Sprintf("kubernetes.io/cluster/%s=owned", cd.Status.InfraID), }, }, } diff --git a/pkg/install/generate_test.go b/pkg/install/generate_test.go index 5d7f1516a7b..0f7025fc573 100644 --- a/pkg/install/generate_test.go +++ b/pkg/install/generate_test.go @@ -15,6 +15,8 @@ const ( testClusterName = "bar" sshKeySecret = "ssh-key" pullSecretSecret = "pull-secret" + testClusterID = "cluster-id" + testInfraID = "infra-id" ) func init() { @@ -68,6 +70,7 @@ func testClusterDeployment() *hivev1.ClusterDeployment { }, Status: hivev1.ClusterDeploymentStatus{ ClusterID: testClusterID, + InfraID: testInfraID, }, } controllerutils.FixupEmptyClusterVersionFields(&cd.Status.ClusterVersionStatus)