Skip to content

Commit

Permalink
kind install works without needing registry flag (#498)
Browse files Browse the repository at this point in the history
Signed-off-by: Paul S. Schweigert <paul@paulschweigert.com>
  • Loading branch information
psschwei authored Mar 7, 2024
1 parent ee6d5ae commit 71de8a6
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions pkg/kind/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ func createKindCluster(registry bool) error {
// temporary warning that registry creation is now opt-in
// remove in v1.12
fmt.Println("\nA local registry is no longer created by default.")
fmt.Println(" To create a local registry, use the --registry flag.")
fmt.Print(" To create a local registry, use the --registry flag.\n\n")
}

if err := checkForExistingCluster(); err != nil {
if err := checkForExistingCluster(registry); err != nil {
return fmt.Errorf("existing cluster: %w", err)
}

Expand Down Expand Up @@ -205,7 +205,7 @@ func checkKindVersion() error {
// checkForExistingCluster checks if the user already has a Kind cluster. If so, it provides
// the option of deleting the existing cluster and recreating it. If not, it proceeds to
// creating a new cluster
func checkForExistingCluster() error {
func checkForExistingCluster(registry bool) error {

getClusters := exec.Command("kind", "get", "clusters", "-q")
out, err := getClusters.CombinedOutput()
Expand All @@ -220,7 +220,7 @@ func checkForExistingCluster() error {
fmt.Print("\nKnative Cluster kind-" + clusterName + " already installed.\nDelete and recreate [y/N]: ")
fmt.Scanf("%s", &resp)
if resp == "y" || resp == "Y" {
if err := recreateCluster(); err != nil {
if err := recreateCluster(registry); err != nil {
return fmt.Errorf("new cluster: %w", err)
}
} else {
Expand All @@ -236,7 +236,7 @@ func checkForExistingCluster() error {
fmt.Print("Knative installation already exists.\nDelete and recreate the cluster [y/N]: ")
fmt.Scanf("%s", &resp)
if resp == "y" || resp == "Y" {
if err := recreateCluster(); err != nil {
if err := recreateCluster(registry); err != nil {
return fmt.Errorf("new cluster: %w", err)
}
} else {
Expand All @@ -251,16 +251,21 @@ func checkForExistingCluster() error {
if err := createNewCluster(); err != nil {
return fmt.Errorf("new cluster: %w", err)
}
if err := connectLocalRegistry(); err != nil {
return fmt.Errorf("local-registry: %w", err)
if registry {
if err := createLocalRegistry(); err != nil {
return fmt.Errorf("%w", err)
}
if err := connectLocalRegistry(); err != nil {
return fmt.Errorf("local-registry: %w", err)
}
}
}

return nil
}

// recreateCluster recreates a Kind cluster
func recreateCluster() error {
func recreateCluster(registry bool) error {
fmt.Println("\n Deleting cluster...")
deleteCluster := exec.Command("kind", "delete", "cluster", "--name", clusterName)
if err := deleteCluster.Run(); err != nil {
Expand All @@ -273,11 +278,13 @@ func recreateCluster() error {
if err := createNewCluster(); err != nil {
return fmt.Errorf("new cluster: %w", err)
}
if err := createLocalRegistry(); err != nil {
return fmt.Errorf("%w", err)
}
if err := connectLocalRegistry(); err != nil {
return fmt.Errorf("local-registry: %w", err)
if registry {
if err := createLocalRegistry(); err != nil {
return fmt.Errorf("%w", err)
}
if err := connectLocalRegistry(); err != nil {
return fmt.Errorf("local-registry: %w", err)
}
}
return nil
}
Expand Down

0 comments on commit 71de8a6

Please sign in to comment.