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
63 changes: 41 additions & 22 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ version="v1.4.7"

[[constraint]]
name = "github.com/openshift/installer"
version = "v0.12.0"
branch = "master"

[[constraint]]
name = "github.com/openshift/generic-admission-server"
Expand All @@ -78,14 +78,10 @@ version="v1.4.7"
branch = "master"
name = "github.com/openshift/api"

[[constraint]]
name = "sigs.k8s.io/cluster-api"
branch = "master"

[[override]]
name = "sigs.k8s.io/cluster-api-provider-aws"
source = "github.com/openshift/cluster-api-provider-aws"
branch = "master"
revision = "15fe4b4ea5636f8516c238490fc6a85d44161181"

[[override]]
name = "github.com/kubernetes-sigs/federation-v2"
Expand Down
18 changes: 8 additions & 10 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 @@ -650,8 +644,12 @@ spec:
type: boolean
federatedClusterRef:
description: FederatedClusterRef is the reference to the federated cluster
resource associated with this ClusterDeployment
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
35 changes: 12 additions & 23 deletions contrib/pkg/installmanager/installmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const (
metadataRelativePath = "metadata.json"
adminKubeConfigRelativePath = "auth/kubeconfig"
adminPasswordRelativePath = "auth/kubeadmin-password"
uuidKey = "openshiftClusterID"
kubernetesKeyPrefix = "kubernetes.io/cluster/"
kubeadminUsername = "kubeadmin"
metadataConfigmapStringTemplate = "%s-metadata"
Expand Down Expand Up @@ -275,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 @@ -319,11 +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{
{uuidKey: clusterID},
{kubernetesKeyPrefix + clusterName: "owned"},
{kubernetesKeyPrefix + infraID: "owned"},
}
uninstaller := &aws.ClusterUninstaller{
Filters: filters,
Expand Down Expand Up @@ -418,23 +417,13 @@ func uploadClusterMetadata(cd *hivev1.ClusterDeployment, m *InstallManager) erro
return err
}

if md.ClusterPlatformMetadata.AWS != nil {
for _, ids := range md.ClusterPlatformMetadata.AWS.Identifier {
clusterID, ok := ids["openshiftClusterID"]
if ok {
cd.Status.ClusterID = clusterID
m.log.WithField("clusterID", clusterID).Debug("found clusterID")
break
}
}
if cd.Status.ClusterID == "" {
m.log.Error("cluster metadata did not contain openshiftClusterID")
return fmt.Errorf("cluster metadata did not contain openshiftClusterID")
}
} else {
// TODO: handle other cloud providers here
return fmt.Errorf("cluster metadata did not contain AWS platform")
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)
err = m.DynamicClient.Status().Update(context.Background(), cd)
if err != nil {
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 @@ -44,13 +44,15 @@ const (
testNamespace = "test-namespace"
// testClusterID matches the json blob below:
testClusterID = "fe953108-f64c-4166-bb8e-20da7665ba00"
// testInfraID matches the json blob below:
testInfraID = "test-cluster-fe9531"

installerBinary = "openshift-install"
fakeInstallerBinary = `#!/bin/sh
echo "Fake Installer"
echo $@
WORKDIR=%s
echo '{"clusterName":"test-cluster","aws":{"region":"us-east-1","identifier":[{"openshiftClusterID":"fe953108-f64c-4166-bb8e-20da7665ba00"}, {"kubernetes.io/cluster/dgoodwin-dev":"owned"}]}}' > $WORKDIR/metadata.json
echo '{"clusterName":"test-cluster","infraID":"test-cluster-fe9531","clusterID":"fe953108-f64c-4166-bb8e-20da7665ba00", "aws":{"region":"us-east-1","identifier":[{"kubernetes.io/cluster/dgoodwin-dev":"owned"}]}}' > $WORKDIR/metadata.json
mkdir -p $WORKDIR/auth/
echo "fakekubeconfig" > $WORKDIR/auth/kubeconfig
echo "fakepassword" > $WORKDIR/auth/kubeadmin-password
Expand Down
3 changes: 1 addition & 2 deletions hack/e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ trap 'teardown' EXIT
# TODO: Determine how to wait for readiness of the validation webhook
sleep 120


i=1
while [ $i -le ${max_tries} ]; do
if [ $i -gt 1 ]; then
Expand All @@ -88,6 +87,7 @@ while [ $i -le ${max_tries} ]; do
AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}" \
AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}" \
BASE_DOMAIN="${BASE_DOMAIN}" \
HIVE_IMAGE="${TEST_IMAGE}" \
INSTALLER_IMAGE="${INSTALLER_IMAGE}" \
OPENSHIFT_RELEASE_IMAGE="" \
TRY_INSTALL_ONCE="true" \
Expand Down Expand Up @@ -133,7 +133,6 @@ if [ $i -ge ${max_tries} ] ; then
exit 10
fi


# Wait for the cluster deployment to be installed
SRC_ROOT=$(git rev-parse --show-toplevel)

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 @@ -199,25 +200,6 @@ func TestClusterDeploymentReconcile(t *testing.T) {
assert.Equal(t, "https://bar-api.clusters.example.com:6443/console", cd.Status.WebConsoleURL)
},
},
{
name: "Parse cluster UUID from metadata",
existing: []runtime.Object{
func() *hivev1.ClusterDeployment {
cd := testClusterDeployment()
cd.Status.Installed = true
return cd
}(),
testInstallJob(),
testSecret(adminPasswordSecret, adminCredsSecretPasswordKey, "password"),
testSecret(pullSecretSecret, pullSecretKey, "{}"),
testSecret(sshKeySecret, adminSSHKeySecretKey, "fakesshkey"),
testMetadataConfigMap(),
},
validate: func(c client.Client, t *testing.T) {
cd := getCD(c)
assert.Equal(t, testClusterID, cd.Status.ClusterID)
},
},
{
name: "Fetch remote cluster version status into clusterdeployment status",
existing: []runtime.Object{
Expand Down Expand Up @@ -435,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
Loading