diff --git a/cli/cmd/plugin/standalone-cluster/cluster/cluster.go b/cli/cmd/plugin/standalone-cluster/cluster/cluster.go index 79dd9f4b0f..09eb87b900 100644 --- a/cli/cmd/plugin/standalone-cluster/cluster/cluster.go +++ b/cli/cmd/plugin/standalone-cluster/cluster/cluster.go @@ -35,10 +35,6 @@ type ClusterManager interface { List() ([]*KubernetesCluster, error) // Delete will destroy a cluster or return an error indicating a problem. Delete(clusterName string) error - // ListNodes returns an array of the node names of the cluster. - // TODO(stmcginnis): Determine if we need to keep this after we sort out the - // antrea hack (hack/patch-node-for-antrea.sh) - ListNodes(clusterName string) []string } // NewClusterManager gets a ClusterManager implementation. diff --git a/cli/cmd/plugin/standalone-cluster/cluster/kind.go b/cli/cmd/plugin/standalone-cluster/cluster/kind.go index 4d2b667328..ba77178485 100644 --- a/cli/cmd/plugin/standalone-cluster/cluster/kind.go +++ b/cli/cmd/plugin/standalone-cluster/cluster/kind.go @@ -8,11 +8,10 @@ import ( "regexp" kindCluster "sigs.k8s.io/kind/pkg/cluster" - "sigs.k8s.io/kind/pkg/cluster/nodes" "sigs.k8s.io/kind/pkg/exec" ) -const KIND_CONFIG = `kind: Cluster +const defaultKindConfig = `kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane @@ -51,7 +50,7 @@ func (kcm KindClusterManager) Create(opts *CreateOpts) (*KubernetesCluster, erro // fmt.Println(err.Error()) // return err // } - parsedKindConfig := []byte(KIND_CONFIG) + parsedKindConfig := []byte(defaultKindConfig) kindConfig := kindCluster.CreateWithRawConfig(parsedKindConfig) err := kindProvider.Create(opts.Name, clusterConfig, kindConfig) if err != nil { @@ -62,6 +61,13 @@ func (kcm KindClusterManager) Create(opts *CreateOpts) (*KubernetesCluster, erro Name: opts.Name, Kubeconfig: opts.KubeconfigPath, } + + // TODO(stmcginnis): This should be conditional based on the CNI chosen. + nodes, _ := kindProvider.ListNodes(opts.Name) + for _, n := range nodes { + patchForAntrea(n.String()) + } + return kc, nil } @@ -97,23 +103,10 @@ func (kcm KindClusterManager) Delete(clusterName string) error { return provider.Delete(clusterName, "") } -// ListNodes returns the name of all nodes in the cluster. -func (kcm KindClusterManager) ListNodes(clusterName string) []string { - provider := kindCluster.NewProvider() - nodes := []nodes.Node{} - nodes, _ = provider.ListNodes(clusterName) - - result := []string{} - for _, n := range nodes { - result = append(result, n.String()) - } - return result -} - -// PatchForAntrea modifies the node network settings to allow local routing. +// patchForAntrea modifies the node network settings to allow local routing. // this needs to happen for antrea running on kind or else you'll lose network connectivity // see: https://github.com/antrea-io/antrea/blob/main/hack/kind-fix-networking.sh -func PatchForAntrea(nodeName string) error { +func patchForAntrea(nodeName string) error { // First need to get the ID of the interface from the cluster node. cmd := exec.Command("docker", "exec", nodeName, "ip", "link") out, err := exec.Output(cmd) diff --git a/cli/cmd/plugin/standalone-cluster/list.go b/cli/cmd/plugin/standalone-cluster/list.go index 81d653a59e..d47985d9c2 100644 --- a/cli/cmd/plugin/standalone-cluster/list.go +++ b/cli/cmd/plugin/standalone-cluster/list.go @@ -41,10 +41,3 @@ func list(cmd *cobra.Command, args []string) error { return nil } - -// ListNodes returns a list of nodes for the current cluster. -// If the cluster doesn't exist, an empty list is returned. -func ListNodes(clusterName string) []string { - clusterManager := cluster.NewClusterManager() - return clusterManager.ListNodes(clusterName) -} diff --git a/cli/cmd/plugin/standalone-cluster/tanzu/tanzu.go b/cli/cmd/plugin/standalone-cluster/tanzu/tanzu.go index 86ed52b4b9..e59577d49a 100644 --- a/cli/cmd/plugin/standalone-cluster/tanzu/tanzu.go +++ b/cli/cmd/plugin/standalone-cluster/tanzu/tanzu.go @@ -3,6 +3,10 @@ package tanzu import ( "fmt" + "os" + "path/filepath" + "time" + "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/packaging/v1alpha1" "github.com/vmware-tanzu/community-edition/cli/cmd/plugin/standalone-cluster/cluster" "github.com/vmware-tanzu/community-edition/cli/cmd/plugin/standalone-cluster/kapp" @@ -10,11 +14,7 @@ import ( logger "github.com/vmware-tanzu/community-edition/cli/cmd/plugin/standalone-cluster/log" "github.com/vmware-tanzu/community-edition/cli/cmd/plugin/standalone-cluster/packages" "github.com/vmware-tanzu/community-edition/cli/cmd/plugin/standalone-cluster/tkr" - "io/ioutil" v1 "k8s.io/api/apps/v1" - "os" - "path/filepath" - "time" ) type TanzuCluster struct { @@ -221,7 +221,7 @@ func installKappController(t *TanzuLocal, kc kapp.KappManager) (*v1.Deployment, } t.kappControllerBundle.SetRelativeConfigPath("config/") - kappValues, err := ioutil.ReadFile("cli/cmd/plugin/standalone-cluster/hack/kapp-values.yaml") + kappValues, err := os.ReadFile("cli/cmd/plugin/standalone-cluster/hack/kapp-values.yaml") if err != nil { return nil, err } @@ -329,10 +329,3 @@ func mergeKubeconfigAndSetContext(mgr kubeconfig.KubeConfigMgr, t *TanzuLocal) e return nil } - -// ListNodes returns a list of nodes for the current cluster. -// If the cluster doesn't exist, an empty list is returned. -func ListNodes(clusterName string) []string { - clusterManager := cluster.NewClusterManager() - return clusterManager.ListNodes(clusterName) -}