Skip to content

Commit 7026956

Browse files
Merge pull request #8565 from patrickdillon/OCPBUGS-35180-multiple-invocations
OCPBUGS-35180: Prevent multiple invocations on CAPI
2 parents 95730fd + 2b3d05a commit 7026956

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
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

pkg/clusterapi/localcontrolplane.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,15 @@ func (c *localControlPlane) Run(ctx context.Context) error {
107107
return err
108108
}
109109

110+
artifactsDirPath := filepath.Join(command.RootOpts.Dir, ArtifactsDir)
111+
err = os.MkdirAll(artifactsDirPath, 0750)
112+
if err != nil {
113+
return fmt.Errorf("error creating cluster-api artifacts directory: %w", err)
114+
}
115+
110116
kc := fromEnvTestConfig(c.Cfg)
111117
{
112-
dir := filepath.Join(command.RootOpts.Dir, "auth")
113-
kf, err := os.Create(filepath.Join(dir, "envtest.kubeconfig"))
118+
kf, err := os.Create(filepath.Join(artifactsDirPath, "envtest.kubeconfig"))
114119
if err != nil {
115120
return err
116121
}

0 commit comments

Comments
 (0)