Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions config/crds/hive_v1alpha1_clusterdeployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -627,7 +622,6 @@ spec:
- state
- startedTime
- completionTime
- version
- payload
type: object
type: array
Expand All @@ -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.
Expand Down
20 changes: 11 additions & 9 deletions contrib/pkg/installmanager/installmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion contrib/pkg/installmanager/installmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion pkg/apis/hive/v1alpha1/clusterdeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const (
testName = "foo-lqmsh"
testClusterName = "bar"
testClusterID = "testFooClusterUUID"
testInfraID = "testFooInfraID"
installJobName = "foo-lqmsh-install"
uninstallJobName = "foo-lqmsh-uninstall"
testNamespace = "default"
Expand Down Expand Up @@ -416,6 +417,7 @@ func testClusterDeployment() *hivev1.ClusterDeployment {
},
Status: hivev1.ClusterDeploymentStatus{
ClusterID: testClusterID,
InfraID: testInfraID,
},
}
controllerutils.FixupEmptyClusterVersionFields(&cd.Status.ClusterVersionStatus)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ func testClusterDeployment() *hivev1.ClusterDeployment {
},
Status: hivev1.ClusterDeploymentStatus{
ClusterID: "cluster-id",
InfraID: "infra-id",
},
}
controllerutils.FixupEmptyClusterVersionFields(&cd.Status.ClusterVersionStatus)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
},
}
}
Expand Down
1 change: 0 additions & 1 deletion pkg/install/convertconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func init() {
const (
testName = "foo"
testNamespace = "default"
testClusterID = "foo"
testAMI = "ami-totallyfake"
adminPassword = "adminpassword"
adminSSHKey = "adminSSH"
Expand Down
2 changes: 1 addition & 1 deletion pkg/install/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
},
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/install/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const (
testClusterName = "bar"
sshKeySecret = "ssh-key"
pullSecretSecret = "pull-secret"
testClusterID = "cluster-id"
testInfraID = "infra-id"
)

func init() {
Expand Down Expand Up @@ -68,6 +70,7 @@ func testClusterDeployment() *hivev1.ClusterDeployment {
},
Status: hivev1.ClusterDeploymentStatus{
ClusterID: testClusterID,
InfraID: testInfraID,
},
}
controllerutils.FixupEmptyClusterVersionFields(&cd.Status.ClusterVersionStatus)
Expand Down