Skip to content
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
12 changes: 6 additions & 6 deletions cli/pkg/kubectl/dev/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func New(streams genericclioptions.IOStreams) (*cobra.Command, error) {
Short: "Manage development environment for kube-bind",
Long: help.Doc(`
Manage a development environment for kube-bind using kind clusters.

This command provides subcommands to initialize and manage kind clusters
configured for kube-bind development.
`),
Expand Down Expand Up @@ -90,13 +90,13 @@ func newInitCommand(streams genericclioptions.IOStreams) (*cobra.Command, error)
Short: "Create development environment with kind cluster and kube-bind backend",
Long: help.Doc(`
Create a complete development environment for kube-bind using kind clusters.

This command will:
- Create a kind cluster configured for kube-bind development
- Add kube-bind.dev.local to /etc/hosts (with sudo prompts if needed)
- Install kube-bind backend helm chart (default: OCI chart from ghcr.io)
- Configure necessary port mappings (8443, 15021)

The backend chart can be sourced from:
- OCI registry (default): oci://ghcr.io/kube-bind/charts/backend
- Local filesystem: --chart-path ./deploy/charts/backend
Expand Down Expand Up @@ -133,7 +133,7 @@ func newDeleteCommand(streams genericclioptions.IOStreams) (*cobra.Command, erro
Short: "Delete development environment",
Long: help.Doc(`
Delete the development environment for kube-bind.

This command will delete the kind cluster created for kube-bind development.
`),
SilenceUsage: true,
Expand All @@ -151,7 +151,7 @@ func newDeleteCommand(streams genericclioptions.IOStreams) (*cobra.Command, erro
return err
}

return opts.RunDelete(cmd.Context())
return opts.RunDelete()
},
}
opts.AddCmdFlags(cmd)
Expand Down Expand Up @@ -182,7 +182,7 @@ func newExampleCommand(streams genericclioptions.IOStreams) (*cobra.Command, err
return err
}

return opts.RunPrintExample(cmd.Context())
return opts.RunPrintExample()
},
}
opts.AddCmdFlags(cmd)
Expand Down
46 changes: 23 additions & 23 deletions cli/pkg/kubectl/dev/plugin/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type DevOptions struct {
WaitForReadyTimeout time.Duration
ChartPath string
ChartVersion string
KindNetwork string
}

// NewDevOptions creates a new DevOptions
Expand All @@ -86,13 +87,14 @@ func (o *DevOptions) AddCmdFlags(cmd *cobra.Command) {
o.Options.BindFlags(cmd)
logsv1.AddFlags(o.Logs, cmd.Flags())

cmd.Flags().StringVarP(&o.ProviderClusterName, "provider-cluster-name", "", "kind-provider", "Name of the provider cluster in dev mode")
cmd.Flags().StringVarP(&o.ConsumerClusterName, "consumer-cluster-name", "", "kind-consumer", "Name of the consumer cluster in dev mode")
cmd.Flags().DurationVarP(&o.WaitForReadyTimeout, "wait-for-ready-timeout", "", 2*time.Minute, "Timeout for waiting for the cluster to be ready")
cmd.Flags().StringVarP(&o.ChartPath, "chart-path", "", o.ChartPath, "Helm chart path or OCI registry URL")
cmd.Flags().StringVarP(&o.ChartVersion, "chart-version", "", o.ChartVersion, "Helm chart version")
cmd.Flags().StringVarP(&o.Image, "image", "", "ghcr.io/kube-bind/backend", "kube-bind backend image to use in dev mode")
cmd.Flags().StringVarP(&o.Tag, "tag", "", "main", "kube-bind backend image tag to use in dev mode")
cmd.Flags().StringVar(&o.ProviderClusterName, "provider-cluster-name", "kind-provider", "Name of the provider cluster in dev mode")
cmd.Flags().StringVar(&o.ConsumerClusterName, "consumer-cluster-name", "kind-consumer", "Name of the consumer cluster in dev mode")
cmd.Flags().DurationVar(&o.WaitForReadyTimeout, "wait-for-ready-timeout", 2*time.Minute, "Timeout for waiting for the cluster to be ready")
cmd.Flags().StringVar(&o.ChartPath, "chart-path", o.ChartPath, "Helm chart path or OCI registry URL")
cmd.Flags().StringVar(&o.ChartVersion, "chart-version", o.ChartVersion, "Helm chart version")
cmd.Flags().StringVar(&o.Image, "image", "ghcr.io/kube-bind/backend", "kube-bind backend image to use in dev mode")
cmd.Flags().StringVar(&o.Tag, "tag", "main", "kube-bind backend image tag to use in dev mode")
cmd.Flags().StringVar(&o.KindNetwork, "kind-network", "kube-bind-dev", "kind network to use in dev mode")
}

// Complete completes the options
Expand Down Expand Up @@ -125,8 +127,6 @@ nodes:
- role: control-plane
`

const dockerNetwork = "kube-bind-dev"

// Color helper functions
func blueCommand(text string) string {
return "\033[38;5;67m" + text + "\033[0m"
Expand All @@ -144,7 +144,7 @@ func (o *DevOptions) runWithColors(ctx context.Context) error {
fmt.Fprintf(o.Streams.ErrOut, "%s kube-bind dev command is in preview\n", redText("EXPERIMENTAL:"))
fmt.Fprintf(o.Streams.ErrOut, "Requirements: Docker must be installed and running\n\n")

hostEntryExists := o.setupHostEntries(ctx)
hostEntryExists := o.setupHostEntries()

if err := o.checkFileLimits(); err != nil {
fmt.Fprintf(o.Streams.ErrOut, "⚠️ File limit check warning: %v\n", err)
Expand All @@ -154,7 +154,7 @@ func (o *DevOptions) runWithColors(ctx context.Context) error {
return err
}

providerIP, err := o.getClusterIPAddress(ctx, o.ProviderClusterName, dockerNetwork)
providerIP, err := o.getClusterIPAddress(ctx, o.ProviderClusterName, o.KindNetwork)
if err != nil {
fmt.Fprintf(o.Streams.ErrOut, "⚠️ Failed to get provider cluster IP address: %v\n", err)
providerIP = ""
Expand Down Expand Up @@ -193,7 +193,7 @@ func (o *DevOptions) runWithColors(ctx context.Context) error {
if providerIP != "" {
fmt.Fprintf(o.Streams.ErrOut, "%s\n", blueCommand(fmt.Sprintf("KUBECONFIG=%s.kubeconfig kubectl bind --konnector-host-alias %s:kube-bind.dev.local", o.ConsumerClusterName, providerIP)))
} else {
fmt.Fprintf(o.Streams.ErrOut, "%s\n", blueCommand(fmt.Sprintf("PROVIDER_IP=$(docker inspect %s-control-plane | jq -r '.[0].NetworkSettings.Networks[\"%s\"].IPAddress') && KUBECONFIG=%s.kubeconfig kubectl bind --konnector-host-alias ${PROVIDER_IP}:kube-bind.dev.local", dockerNetwork, o.ProviderClusterName, o.ConsumerClusterName)))
fmt.Fprintf(o.Streams.ErrOut, "%s\n", blueCommand(fmt.Sprintf("PROVIDER_IP=$(docker inspect %s-control-plane | jq -r '.[0].NetworkSettings.Networks[\"%s\"].IPAddress') && KUBECONFIG=%s.kubeconfig kubectl bind --konnector-host-alias ${PROVIDER_IP}:kube-bind.dev.local", o.KindNetwork, o.ProviderClusterName, o.ConsumerClusterName)))
}

return nil
Expand All @@ -204,7 +204,7 @@ func (o *DevOptions) Run(ctx context.Context) error {
return o.runWithColors(ctx)
}

func (o *DevOptions) setupHostEntries(ctx context.Context) bool {
func (o *DevOptions) setupHostEntries() bool {
if err := addHostEntry("kube-bind.dev.local"); err != nil {
fmt.Fprintf(o.Streams.ErrOut, "Warning: Could not automatically add host entry. Please run:\n")
if runtime.GOOS == "windows" {
Expand All @@ -222,7 +222,7 @@ func (o *DevOptions) setupHostEntries(ctx context.Context) bool {

func (o *DevOptions) createCluster(ctx context.Context, clusterName, clusterConfig string, installKubeBind bool) error {
// Set experimental Docker network for kind clusters to communicate
os.Setenv("KIND_EXPERIMENTAL_DOCKER_NETWORK", dockerNetwork)
os.Setenv("KIND_EXPERIMENTAL_DOCKER_NETWORK", o.KindNetwork)

provider := cluster.NewProvider()

Expand All @@ -236,7 +236,7 @@ func (o *DevOptions) createCluster(ctx context.Context, clusterName, clusterConf
if slices.Contains(clusters, clusterName) {
fmt.Fprint(o.Streams.ErrOut, "Kind cluster "+clusterName+" already exists, skipping creation\n")
} else {
fmt.Fprintf(o.Streams.ErrOut, "Creating kind cluster %s with network %s\n", clusterName, dockerNetwork)
fmt.Fprintf(o.Streams.ErrOut, "Creating kind cluster %s with network %s\n", clusterName, o.KindNetwork)
err := provider.Create(clusterName,
cluster.CreateWithRawConfig([]byte(clusterConfig)),
cluster.CreateWithWaitForReady(o.WaitForReadyTimeout),
Expand Down Expand Up @@ -304,7 +304,7 @@ func (o *DevOptions) getClusterIPAddress(ctx context.Context, clusterName, netwo
func (o *DevOptions) installHelmChart(_ context.Context, restConfig *rest.Config) error {
actionConfig := new(action.Configuration)

if err := actionConfig.Init(&restConfigGetter{config: restConfig}, "kube-bind", "secret", func(format string, v ...interface{}) {}); err != nil {
if err := actionConfig.Init(&restConfigGetter{config: restConfig}, "kube-bind", "secret", func(format string, v ...any) {}); err != nil {
return fmt.Errorf("failed to initialize helm action config: %w", err)
}

Expand All @@ -315,32 +315,32 @@ func (o *DevOptions) installHelmChart(_ context.Context, restConfig *rest.Config
}
actionConfig.RegistryClient = registryClient

values := map[string]interface{}{
"image": map[string]interface{}{
values := map[string]any{
"image": map[string]any{
"repository": o.Image,
"tag": o.Tag,
},
"examples": map[string]interface{}{
"examples": map[string]any{
"enabled": true,
},
"backend": map[string]interface{}{
"backend": map[string]any{
"listenAddress": "0.0.0.0:8080",
"namespacePrefix": "kube-bind-",
"externalAddress": "https://kube-bind.dev.local:6443",
"externalServerName": "kind-provider-control-plane",
"consumerScope": "cluster",
"oidc": map[string]interface{}{
"oidc": map[string]any{
"callbackUrl": "http://kube-bind.dev.local:8080/api/callback",
"issuerUrl": "http://kube-bind.dev.local:8080/oidc",
"type": "embedded",
},
},
"service": map[string]interface{}{
"service": map[string]any{
"type": "NodePort",
"port": 8080,
"nodePort": 31000,
},
"hostAliases": []map[string]interface{}{
"hostAliases": []map[string]any{
{
"ip": "0.0.0.0",
"hostnames": []string{"kube-bind.dev.local"},
Expand Down
13 changes: 6 additions & 7 deletions cli/pkg/kubectl/dev/plugin/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,26 @@ limitations under the License.
package plugin

import (
"context"
"fmt"
"os"
"runtime"

"sigs.k8s.io/kind/pkg/cluster"
)

func (o *DevOptions) RunDelete(ctx context.Context) error {
if err := o.deleteCluster(ctx, o.ProviderClusterName); err != nil {
func (o *DevOptions) RunDelete() error {
if err := o.deleteCluster(o.ProviderClusterName); err != nil {
return err
}

if err := o.deleteCluster(ctx, o.ConsumerClusterName); err != nil {
if err := o.deleteCluster(o.ConsumerClusterName); err != nil {
return err
}

return o.cleanupHostEntries(ctx)
return o.cleanupHostEntries()
}

func (o *DevOptions) deleteCluster(ctx context.Context, clusterName string) error {
func (o *DevOptions) deleteCluster(clusterName string) error {
fmt.Fprintf(o.Streams.ErrOut, "Deleting kind cluster %s\n", clusterName)
provider := cluster.NewProvider()

Expand All @@ -56,7 +55,7 @@ func (o *DevOptions) deleteCluster(ctx context.Context, clusterName string) erro
return nil
}

func (o *DevOptions) cleanupHostEntries(ctx context.Context) error {
func (o *DevOptions) cleanupHostEntries() error {
if err := removeHostEntry("kube-bind.dev.local"); err != nil {
fmt.Fprintf(o.Streams.ErrOut, "Failed to remove host entry: %v\n", err)
fmt.Fprintf(o.Streams.ErrOut, "Warning: Could not automatically remove host entry. Please run:\n")
Expand Down
3 changes: 1 addition & 2 deletions cli/pkg/kubectl/dev/plugin/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package plugin

import (
"context"
"fmt"
)

Expand All @@ -29,7 +28,7 @@ metadata:
spec:
tier: Dedicated`

func (o *DevOptions) RunPrintExample(ctx context.Context) error {
func (o *DevOptions) RunPrintExample() error {
fmt.Fprintf(o.Streams.Out, "%s", example)
return nil
}