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

Commit

Permalink
Implements using node image from TKR (#2350)
Browse files Browse the repository at this point in the history
Signed-off-by: John McBride <[email protected]>
  • Loading branch information
jpmcb authored Oct 26, 2021
1 parent 370ca1c commit 52862b7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
13 changes: 1 addition & 12 deletions cli/cmd/plugin/standalone-cluster/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,13 @@ type KubernetesCluster struct {
Kubeconfig string
}

// CreateOpts contains data to be used when creating a new cluster.
type CreateOpts struct {
// Name is the name for the new cluster.
Name string
// KubeconfigPath is the path to the kubeconfig to use.
KubeconfigPath string
// Config contains the full cluster creation details passed in from the user when calling
// create.
Config *config.LocalClusterConfig
}

// ClusterManager provides methods for creating and managing Kubernetes
// clusters.
//nolint:golint
type ClusterManager interface {
// Create will create a new cluster or return an error indicating a problem
// during creation.
Create(opts *CreateOpts) (*KubernetesCluster, error)
Create(c *config.LocalClusterConfig) (*KubernetesCluster, error)
// Get retrieves cluster information or return an error indicating a problem.
Get(clusterName string) (*KubernetesCluster, error)
// List gets a list of all local clusters.
Expand Down
15 changes: 8 additions & 7 deletions cli/cmd/plugin/standalone-cluster/cluster/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,26 @@ type KindClusterManager struct {
}

// Create will create a new kind cluster or return an error.
func (kcm KindClusterManager) Create(opts *CreateOpts) (*KubernetesCluster, error) {
func (kcm KindClusterManager) Create(c *config.LocalClusterConfig) (*KubernetesCluster, error) {
kindProvider := kindCluster.NewProvider()
clusterConfig := kindCluster.CreateWithKubeconfigPath(opts.KubeconfigPath)
clusterConfig := kindCluster.CreateWithKubeconfigPath(c.KubeconfigPath)
nodeConfig := kindCluster.CreateWithNodeImage(c.NodeImage)

// TODO(stmcginnis): Determine what we need to do for kind configuration
parsedKindConfig := []byte(defaultKindConfig)
kindConfig := kindCluster.CreateWithRawConfig(parsedKindConfig)
err := kindProvider.Create(opts.Name, clusterConfig, kindConfig)
err := kindProvider.Create(c.ClusterName, clusterConfig, kindConfig, nodeConfig)
if err != nil {
return nil, err
}

kc := &KubernetesCluster{
Name: opts.Name,
Kubeconfig: opts.KubeconfigPath,
Name: c.ClusterName,
Kubeconfig: c.KubeconfigPath,
}

if strings.Contains(opts.Config.Cni, "antrea") {
nodes, _ := kindProvider.ListNodes(opts.Name)
if strings.Contains(c.Cni, "antrea") {
nodes, _ := kindProvider.ListNodes(c.ClusterName)
for _, n := range nodes {
if err := patchForAntrea(n.String()); err != nil { //nolint:staticcheck
// TODO(stmcginnis): We probably don't want to just error out
Expand Down
6 changes: 6 additions & 0 deletions cli/cmd/plugin/standalone-cluster/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ type PortMap struct {
type LocalClusterConfig struct {
// ClusterName is the name of the cluster.
ClusterName string `yaml:"ClusterName"`
// KubeconfigPath is the path to the kubeconfig to use.
KubeconfigPath string `yaml:"KubeconfigPath"`
// NodeImage is the host OS image to use for Kubernetes nodes.
// It is typically resolved, automatically, in the Taznu Kubernetes Release (TKR) BOM,
// but also can be overridden in configuration.
NodeImage string `yaml:"NodeImage"`
// Provider is the local infrastructure provider to use (e.g. kind).
Provider string `yaml:"Provider"`
// ProviderConfiguration offers optional provider-specific configuration.
Expand Down
10 changes: 4 additions & 6 deletions cli/cmd/plugin/standalone-cluster/tanzu/tanzu.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ func (t *TanzuLocal) Deploy(lcConfig *config.LocalClusterConfig) error {
// base image
log.Event("\\U+1F5BC", " Selected base image\n")
log.Style(outputIndent, logger.ColorLightGrey).Infof("%s\n", t.bom.GetTKRNodeImage())
lcConfig.NodeImage = t.bom.GetTKRNodeImage()

// core package repository
log.Event("\\U+1F4E6", "Selected core package repository\n")
log.Style(outputIndent, logger.ColorLightGrey).Infof("%s\n", t.bom.GetTKRCoreRepoBundlePath())
Expand Down Expand Up @@ -506,12 +508,8 @@ func runClusterCreate(lcConfig *config.LocalClusterConfig) (*cluster.KubernetesC
}
kcPath := filepath.Join(clusterDir, "kube.conf")
clusterManager := cluster.NewKindClusterManager()
clusterCreateOpts := cluster.CreateOpts{
Name: lcConfig.ClusterName,
KubeconfigPath: kcPath,
Config: lcConfig,
}
kc, err := clusterManager.Create(&clusterCreateOpts)
lcConfig.KubeconfigPath = kcPath
kc, err := clusterManager.Create(lcConfig)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 52862b7

Please sign in to comment.