Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Ipv4 cidr in cilium #12587

Merged
merged 2 commits into from
Oct 15, 2021
Merged
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
50 changes: 42 additions & 8 deletions pkg/minikube/cni/cilium.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ limitations under the License.
package cni

import (
"bytes"
"os/exec"
"text/template"

"github.com/pkg/errors"
"k8s.io/klog/v2"
"k8s.io/minikube/pkg/minikube/config"
)

// From https://github.com/raw/cilium/cilium/v1.9/install/kubernetes/quick-install.yaml
var ciliumTmpl = `---
var ciliumTmpl = template.Must(template.New("name").Parse(
`---
# Source: cilium/templates/cilium-agent-serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
Expand Down Expand Up @@ -175,7 +179,7 @@ data:
hubble-tls-key-file: /var/lib/cilium/tls/hubble/server.key
hubble-tls-client-ca-files: /var/lib/cilium/tls/hubble/client-ca.crt
ipam: "cluster-pool"
cluster-pool-ipv4-cidr: "10.0.0.0/8"
cluster-pool-ipv4-cidr: "{{.PodSubnet }}"
cluster-pool-ipv4-mask-size: "24"
disable-cnp-status-updates: "true"
cgroup-root: "/run/cilium/cgroupv2"
Expand Down Expand Up @@ -786,7 +790,8 @@ spec:
- configMap:
name: cilium-config
name: cilium-config-path
`
`,
))

// Cilium is the Cilium CNI manager
type Cilium struct {
Expand All @@ -798,17 +803,46 @@ func (c Cilium) String() string {
return "Cilium"
}

// CIDR returns the default CIDR used by this CNI
func (c Cilium) CIDR() string {
return DefaultPodCIDR
}

// GenerateKubeadmYAML generates the .yaml file
func GenerateCiliumYAML() ([]byte, error) {

podCIDR := DefaultPodCIDR

klog.Infof("Using pod CIDR: %s", podCIDR)

opts := struct {
PodSubnet string
}{
PodSubnet: podCIDR,
}

b := bytes.Buffer{}
configTmpl := ciliumTmpl

klog.Infof("cilium options: %+v", opts)
if err := configTmpl.Execute(&b, opts); err != nil {
return nil, err
}
klog.Infof("cilium config:\n%s\n", b.String())
return b.Bytes(), nil
}

// Apply enables the CNI
func (c Cilium) Apply(r Runner) error {
// see https://kubernetes.io/docs/tasks/administer-cluster/network-policy-provider/cilium-network-policy/
if _, err := r.RunCmd(exec.Command("sudo", "/bin/bash", "-c", "grep 'bpffs /sys/fs/bpf' /proc/mounts || sudo mount bpffs -t bpf /sys/fs/bpf")); err != nil {
return errors.Wrap(err, "bpf mount")
}

return applyManifest(c.cc, r, manifestAsset([]byte(ciliumTmpl)))
}
ciliumCfg, err := GenerateCiliumYAML()
if err != nil {
return errors.Wrap(err, "generating cilium cfg")
}

// CIDR returns the default CIDR used by this CNI
func (c Cilium) CIDR() string {
return DefaultPodCIDR
return applyManifest(c.cc, r, manifestAsset(ciliumCfg))
}