Skip to content

Commit 2b3d05a

Browse files
committed
pkg/asset/cluster: stop re-entry in capi installs
This commit prevents users from restarting an aborted install, i.e. from running create cluster multiple times. This check is a guardrail that parallels the functionality with terraform installs. CAPI installs should be re-entrant, and in my experience this has generally worked fine, but it is not (yet) well tested. Because this functionality can work and is useful, the commit includes an environment variable to allow opting in for re-entry.
1 parent 997c2ee commit 2b3d05a

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

pkg/asset/cluster/cluster.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cluster
33
import (
44
"context"
55
"fmt"
6+
"os"
67
"path/filepath"
78
"strings"
89

@@ -24,6 +25,7 @@ import (
2425
"github.com/openshift/installer/pkg/asset/password"
2526
"github.com/openshift/installer/pkg/asset/quota"
2627
"github.com/openshift/installer/pkg/asset/rhcos"
28+
"github.com/openshift/installer/pkg/clusterapi"
2729
infra "github.com/openshift/installer/pkg/infrastructure/platform"
2830
typesaws "github.com/openshift/installer/pkg/types/aws"
2931
typesazure "github.com/openshift/installer/pkg/types/azure"
@@ -161,9 +163,21 @@ func (c *Cluster) Load(f asset.FileFetcher) (found bool, err error) {
161163
return true, err
162164
}
163165
if len(matches) != 0 {
164-
return true, errors.Errorf("terraform state files alread exist. There may already be a running cluster")
166+
return true, fmt.Errorf("terraform state files already exist. There may already be a running cluster")
165167
}
166168

169+
matches, err = filepath.Glob(filepath.Join(InstallDir, clusterapi.ArtifactsDir, "envtest.kubeconfig"))
170+
if err != nil {
171+
return true, fmt.Errorf("error checking for existence of envtest.kubeconfig: %w", err)
172+
}
173+
174+
// Cluster-API based installs can be re-entered, but this is an experimental feature
175+
// that should be opted into and only used for testing and development.
176+
reentrant := strings.EqualFold(os.Getenv("OPENSHIFT_INSTALL_REENTRANT"), "true")
177+
178+
if !reentrant && len(matches) != 0 {
179+
return true, fmt.Errorf("local infrastructure provisioning artifacts already exist. There may already be a running cluster")
180+
}
167181
return false, nil
168182
}
169183

0 commit comments

Comments
 (0)