Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Move antrea network patching to kind create #2290

Merged
Merged
Show file tree
Hide file tree
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
4 changes: 0 additions & 4 deletions cli/cmd/plugin/standalone-cluster/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 11 additions & 18 deletions cli/cmd/plugin/standalone-cluster/cluster/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down Expand Up @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions cli/cmd/plugin/standalone-cluster/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
17 changes: 5 additions & 12 deletions cli/cmd/plugin/standalone-cluster/tanzu/tanzu.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ 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"
"github.com/vmware-tanzu/community-edition/cli/cmd/plugin/standalone-cluster/kubeconfig"
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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}