Skip to content

Commit

Permalink
patch kindnetd for backwards compatibility
Browse files Browse the repository at this point in the history
patch cni only if asked to do so
  • Loading branch information
Antonio Ojea committed Feb 20, 2021
1 parent 66f0a2d commit 69d3b16
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/build/nodeimage/const_cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ The default CNI manifest and images are our own tiny kindnet

var defaultCNIImages = []string{"kindest/kindnetd:v20210119-d5ef916d"}

// TODO: migrate to fully patching and deprecate the template
const defaultCNIManifest = `
# kindnetd networking manifest
# would you kindly template this file
# would you kindly patch this file
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
Expand Down
36 changes: 36 additions & 0 deletions pkg/cluster/internal/create/actions/installcni/cni.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import (
"text/template"

"sigs.k8s.io/kind/pkg/errors"
"sigs.k8s.io/kind/pkg/internal/apis/config"

"sigs.k8s.io/kind/pkg/cluster/internal/create/actions"
"sigs.k8s.io/kind/pkg/cluster/internal/patch"
"sigs.k8s.io/kind/pkg/cluster/nodeutils"
)

Expand Down Expand Up @@ -83,6 +85,40 @@ func (a *action) Execute(ctx *actions.ActionContext) error {
manifest = out.String()
}

// NOTE: this is intentionally undocumented, as an internal implementation
// detail. Going forward users should disable the default CNI and install
// their own, or use the default. The internal templating mechanism is
// not intended for external usage and is unstable.
if strings.Contains(manifest, "would you kindly patch this file") {
// Add the controlplane endpoint so kindnet doesn´t have to wait for kube-proxy
controlPlaneEndpoint, err := ctx.Provider.GetAPIServerInternalEndpoint(ctx.Config.Name)
if err != nil {
return err
}

patchValue := `
- op: add
path: /spec/template/spec/containers/0/env/-
value:
name: CONTROL_PLANE_ENDPOINT
value: ` + controlPlaneEndpoint

controlPlanePatch6902 := config.PatchJSON6902{
Group: "apps",
Version: "v1",
Kind: "DaemonSet",
Patch: patchValue,
}

patchedConfig, err := patch.KubeYAML(manifest, nil, []config.PatchJSON6902{controlPlanePatch6902})
if err != nil {
return err
}
manifest = patchedConfig
}

ctx.Logger.V(5).Infof("Using the following Kindnetd config:\n%s", manifest)

// install the manifest
if err := node.Command(
"kubectl", "create", "--kubeconfig=/etc/kubernetes/admin.conf",
Expand Down

0 comments on commit 69d3b16

Please sign in to comment.