Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kind install works without needing registry flag #498

Merged
merged 1 commit into from
Mar 7, 2024
Merged
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
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
Loading