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

chore: simplify addons config for calico and flannel #3773

Merged
merged 7 commits into from
Sep 2, 2020
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
21 changes: 13 additions & 8 deletions parts/k8s/addons/1.15/calico.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ data:
"datastore_type": "kubernetes",
"nodename": "__KUBERNETES_NODE_NAME__",
"mtu": 1500,
"ipam": <calicoIPAMConfig>,
{{- if not IsAzureCNI}}
"ipam": {
"type": "host-local",
"subnet": "usePodCidr"
},
{{- end}}
"policy": {
"type": "k8s"
},
Expand Down Expand Up @@ -394,7 +399,7 @@ spec:
- name: USE_POD_CIDR
value: "true"
- name: FELIX_INTERFACEPREFIX
value: "azv"
value: "{{if IsAzureCNI}}azv{{else}}cali{{end}}"
# Uncomment these lines to enable prometheus metrics. Since Typha is host-networked,
# this opens a port on the host, which may need to be secured.
#- name: TYPHA_PROMETHEUSMETRICSENABLED
Expand Down Expand Up @@ -464,8 +469,8 @@ spec:
terminationGracePeriodSeconds: 0
priorityClassName: system-node-critical
initContainers:
{{- /* Start of install-cni initContainer
This container installs the CNI binaries
{{- if not IsAzureCNI}}
{{- /* This container installs the CNI binaries
and CNI network config file on each node. */}}
- name: install-cni
image: {{ContainerImage "calico-cni"}}
Expand Down Expand Up @@ -493,8 +498,8 @@ spec:
name: cni-bin-dir
- mountPath: /host/etc/cni/net.d
name: cni-net-dir
{{- /* End of install-cni initContainer
Adds a Flex Volume Driver that creates a per-pod Unix Domain Socket to allow Dikastes
{{- end}}
{{- /* Adds a Flex Volume Driver that creates a per-pod Unix Domain Socket to allow Dikastes
to communicate with Felix over the Policy Sync API. */}}
- name: flexvol-driver
image: {{ContainerImage "calico-pod2daemon"}}
Expand Down Expand Up @@ -538,7 +543,7 @@ spec:
chosen from this range. Changing this value after installation will have
no effect. This should fall within `--cluster-cidr`. */}}
- name: CALICO_IPV4POOL_CIDR
value: "<kubeClusterCidr>"
value: "{{GetClusterSubnet}}"
{{- /* Disable file logging so `kubectl logs` works. */}}
- name: CALICO_DISABLE_FILE_LOGGING
value: "true"
Expand All @@ -556,7 +561,7 @@ spec:
- name: CALICO_IPV4POOL_IPIP
value: "off"
- name: FELIX_INTERFACEPREFIX
value: "azv"
value: "{{if IsAzureCNI}}azv{{else}}cali{{end}}"
securityContext:
privileged: true
resources:
Expand Down
13 changes: 9 additions & 4 deletions parts/k8s/addons/calico.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ data:
"datastore_type": "kubernetes",
"nodename": "__KUBERNETES_NODE_NAME__",
"mtu": 1500,
"ipam": <calicoIPAMConfig>,
{{- if not IsAzureCNI}}
"ipam": {
"type": "host-local",
"subnet": "usePodCidr"
},
{{- end}}
"policy": {
"type": "k8s"
},
Expand Down Expand Up @@ -392,7 +397,7 @@ spec:
- name: USE_POD_CIDR
value: "true"
- name: FELIX_INTERFACEPREFIX
value: "azv"
value: "{{if IsAzureCNI}}azv{{else}}cali{{end}}"
# Uncomment these lines to enable prometheus metrics. Since Typha is host-networked,
# this opens a port on the host, which may need to be secured.
#- name: TYPHA_PROMETHEUSMETRICSENABLED
Expand Down Expand Up @@ -525,7 +530,7 @@ spec:
chosen from this range. Changing this value after installation will have
no effect. This should fall within `--cluster-cidr`. */}}
- name: CALICO_IPV4POOL_CIDR
value: "<kubeClusterCidr>"
value: "{{GetClusterSubnet}}"
{{- /* Disable file logging so `kubectl logs` works. */}}
- name: CALICO_DISABLE_FILE_LOGGING
value: "true"
Expand All @@ -543,7 +548,7 @@ spec:
- name: CALICO_IPV4POOL_IPIP
value: "off"
- name: FELIX_INTERFACEPREFIX
value: "azv"
value: "{{if IsAzureCNI}}azv{{else}}cali{{end}}"
- name: FELIX_USAGEREPORTINGENABLED
value: "{{ContainerConfig "usageReportingEnabled"}}"
securityContext:
Expand Down
2 changes: 1 addition & 1 deletion parts/k8s/addons/flannel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ data:
}
net-conf.json: |
{
"Network": "<kubeClusterCidr>",
"Network": "{{GetClusterSubnet}}",
"Backend": {
"Type": "vxlan"
}
Expand Down
12 changes: 0 additions & 12 deletions parts/k8s/cloud-init/masternodecustomdata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -466,18 +466,6 @@ MASTER_CONTAINER_ADDONS_PLACEHOLDER
sed -i "s|<advertiseAddr>|$PRIVATE_IP|g" /etc/kubernetes/manifests/kube-apiserver.yaml
{{- if EnableDataEncryptionAtRest }}
sed -i "s|<etcdEncryptionSecret>|\"{{WrapAsParameter "etcdEncryptionKey"}}\"|g" /etc/kubernetes/encryption-config.yaml
{{end}}
{{- if eq .OrchestratorProfile.KubernetesConfig.NetworkPolicy "calico"}}
sed -i "s|<kubeClusterCidr>|{{WrapAsParameter "kubeClusterCidr"}}|g" /etc/kubernetes/addons/calico.yaml
{{- if eq .OrchestratorProfile.KubernetesConfig.NetworkPlugin "azure"}}
sed -i "/Start of install-cni initContainer/,/End of install-cni initContainer/d" /etc/kubernetes/addons/calico.yaml
{{else}}
sed -i "s|<calicoIPAMConfig>|{\"type\": \"host-local\", \"subnet\": \"usePodCidr\"}|g" /etc/kubernetes/addons/calico.yaml
sed -i "s|azv|cali|g" /etc/kubernetes/addons/calico.yaml
{{end}}
{{end}}
{{- if eq .OrchestratorProfile.KubernetesConfig.NetworkPlugin "flannel"}}
sed -i "s|<kubeClusterCidr>|{{WrapAsParameter "kubeClusterCidr"}}|g" /etc/kubernetes/addons/flannel.yaml
{{end}}
#EOF

Expand Down
6 changes: 6 additions & 0 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,12 @@ func getAddonFuncMap(addon api.KubernetesAddon, cs *api.ContainerService) templa
"GetMode": func() string {
return addon.Mode
},
"GetClusterSubnet": func() string {
return cs.Properties.OrchestratorProfile.KubernetesConfig.ClusterSubnet
},
"IsAzureCNI": func() bool {
return cs.Properties.OrchestratorProfile.IsAzureCNI()
},
}
}

Expand Down
129 changes: 123 additions & 6 deletions pkg/engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2495,6 +2495,8 @@ func TestGetAddonFuncMap(t *testing.T) {
expectedShouldEnableAzureFileCSISnapshotFeature bool
expectedIsKubernetesVersionGeOneDotSixteenDotZero bool
expectedMode string
expectedGetClusterSubnet string
expectedIsAzureCNI bool
}{
{
name: "coredns as an example",
Expand Down Expand Up @@ -2542,6 +2544,7 @@ func TestGetAddonFuncMap(t *testing.T) {
},
},
},
ClusterSubnet: "10.239.0.0/16",
},
},
AgentPoolProfiles: []*api.AgentPoolProfile{
Expand Down Expand Up @@ -2573,7 +2576,9 @@ func TestGetAddonFuncMap(t *testing.T) {
expectedShouldEnableAzureDiskCSISnapshotFeature: false,
expectedShouldEnableAzureFileCSISnapshotFeature: true,
expectedIsKubernetesVersionGeOneDotSixteenDotZero: false,
expectedMode: api.AddonModeEnsureExists,
expectedMode: api.AddonModeEnsureExists,
expectedGetClusterSubnet: "10.239.0.0/16",
expectedIsAzureCNI: true,
},
{
name: "coredns as an example - Azure Stack",
Expand Down Expand Up @@ -2621,6 +2626,7 @@ func TestGetAddonFuncMap(t *testing.T) {
},
},
},
ClusterSubnet: "10.239.0.0/16",
},
},
AgentPoolProfiles: []*api.AgentPoolProfile{
Expand Down Expand Up @@ -2656,7 +2662,9 @@ func TestGetAddonFuncMap(t *testing.T) {
expectedShouldEnableAzureDiskCSISnapshotFeature: false,
expectedShouldEnableAzureFileCSISnapshotFeature: true,
expectedIsKubernetesVersionGeOneDotSixteenDotZero: false,
expectedMode: api.AddonModeEnsureExists,
expectedMode: api.AddonModeEnsureExists,
expectedGetClusterSubnet: "10.239.0.0/16",
expectedIsAzureCNI: true,
},
{
name: "coredns as an example - StorageAccount",
Expand Down Expand Up @@ -2704,6 +2712,7 @@ func TestGetAddonFuncMap(t *testing.T) {
},
},
},
ClusterSubnet: "10.239.0.0/16",
},
},
AgentPoolProfiles: []*api.AgentPoolProfile{
Expand Down Expand Up @@ -2735,7 +2744,9 @@ func TestGetAddonFuncMap(t *testing.T) {
expectedShouldEnableAzureDiskCSISnapshotFeature: false,
expectedShouldEnableAzureFileCSISnapshotFeature: true,
expectedIsKubernetesVersionGeOneDotSixteenDotZero: false,
expectedMode: api.AddonModeEnsureExists,
expectedMode: api.AddonModeEnsureExists,
expectedGetClusterSubnet: "10.239.0.0/16",
expectedIsAzureCNI: true,
},
{
name: "coredns as an example - CCM",
Expand Down Expand Up @@ -2784,6 +2795,7 @@ func TestGetAddonFuncMap(t *testing.T) {
},
},
},
ClusterSubnet: "10.239.0.0/16",
},
},
AgentPoolProfiles: []*api.AgentPoolProfile{
Expand Down Expand Up @@ -2815,7 +2827,9 @@ func TestGetAddonFuncMap(t *testing.T) {
expectedShouldEnableAzureDiskCSISnapshotFeature: false,
expectedShouldEnableAzureFileCSISnapshotFeature: true,
expectedIsKubernetesVersionGeOneDotSixteenDotZero: false,
expectedMode: api.AddonModeEnsureExists,
expectedMode: api.AddonModeEnsureExists,
expectedGetClusterSubnet: "10.239.0.0/16",
expectedIsAzureCNI: true,
},
{
name: "coredns as an example - Availability Zones",
Expand Down Expand Up @@ -2865,6 +2879,7 @@ func TestGetAddonFuncMap(t *testing.T) {
},
},
},
ClusterSubnet: "10.239.0.0/16",
},
},
AgentPoolProfiles: []*api.AgentPoolProfile{
Expand Down Expand Up @@ -2900,7 +2915,9 @@ func TestGetAddonFuncMap(t *testing.T) {
expectedShouldEnableAzureDiskCSISnapshotFeature: true,
expectedShouldEnableAzureFileCSISnapshotFeature: false,
expectedIsKubernetesVersionGeOneDotSixteenDotZero: true,
expectedMode: api.AddonModeEnsureExists,
expectedMode: api.AddonModeEnsureExists,
expectedGetClusterSubnet: "10.239.0.0/16",
expectedIsAzureCNI: true,
},
{
name: "coredns as an example - hybrid cluster",
Expand Down Expand Up @@ -2950,6 +2967,7 @@ func TestGetAddonFuncMap(t *testing.T) {
},
},
},
ClusterSubnet: "10.239.0.0/16",
},
},
AgentPoolProfiles: []*api.AgentPoolProfile{
Expand Down Expand Up @@ -2984,7 +3002,96 @@ func TestGetAddonFuncMap(t *testing.T) {
expectedShouldEnableAzureDiskCSISnapshotFeature: true,
expectedShouldEnableAzureFileCSISnapshotFeature: false,
expectedIsKubernetesVersionGeOneDotSixteenDotZero: true,
expectedMode: api.AddonModeReconcile,
expectedMode: api.AddonModeReconcile,
expectedGetClusterSubnet: "10.239.0.0/16",
expectedIsAzureCNI: true,
},
{
name: "coredns as an example - kubenet",
addon: api.KubernetesAddon{
Name: common.CoreDNSAddonName,
Enabled: to.BoolPtr(true),
Mode: api.AddonModeReconcile,
Config: map[string]string{
"foo": "bar",
},
Containers: []api.KubernetesContainerSpec{
{
Name: common.CoreDNSAddonName,
CPURequests: "100m",
MemoryRequests: "300Mi",
CPULimits: "100m",
MemoryLimits: "300Mi",
Image: specConfig.KubernetesImageBase + k8sComponentsByVersionMap["1.15.4"][common.CoreDNSAddonName],
},
},
},
cs: &api.ContainerService{
Location: "eastus2",
Properties: &api.Properties{
OrchestratorProfile: &api.OrchestratorProfile{
OrchestratorType: api.Kubernetes,
OrchestratorVersion: "1.18.0",
KubernetesConfig: &api.KubernetesConfig{
UseCloudControllerManager: to.BoolPtr(true),
NetworkPlugin: api.NetworkPluginKubenet,
Addons: []api.KubernetesAddon{
{
Name: common.CoreDNSAddonName,
Enabled: to.BoolPtr(true),
Config: map[string]string{
"foo": "bar",
},
Containers: []api.KubernetesContainerSpec{
{
Name: common.CoreDNSAddonName,
CPURequests: "100m",
MemoryRequests: "300Mi",
CPULimits: "100m",
MemoryLimits: "300Mi",
Image: specConfig.KubernetesImageBase + k8sComponentsByVersionMap["1.15.4"][common.CoreDNSAddonName],
},
},
},
},
ClusterSubnet: "10.239.0.0/16",
},
},
AgentPoolProfiles: []*api.AgentPoolProfile{
{
Name: "pool1",
Count: 1,
AvailabilityProfile: api.VirtualMachineScaleSets,
StorageProfile: api.ManagedDisks,
OSType: api.Windows,
},
{
Name: "pool2",
Count: 1,
AvailabilityProfile: api.VirtualMachineScaleSets,
StorageProfile: api.ManagedDisks,
OSType: api.Linux,
},
},
},
},
expectedImage: specConfig.KubernetesImageBase + k8sComponentsByVersionMap["1.15.4"][common.CoreDNSAddonName],
expectedCPUReqs: "100m",
expectedCPULimits: "100m",
expectedMemReqs: "300Mi",
expectedMemLimits: "300Mi",
expectedFoo: "bar",
expectedNeedsManagedDiskStorageClasses: true,
expectedUsesCloudControllerManager: true,
expectedHasWindows: true,
expectedHasLinux: true,
expectedCSIControllerReplicas: "2",
expectedShouldEnableAzureDiskCSISnapshotFeature: true,
expectedShouldEnableAzureFileCSISnapshotFeature: false,
expectedIsKubernetesVersionGeOneDotSixteenDotZero: true,
expectedMode: api.AddonModeReconcile,
expectedGetClusterSubnet: "10.239.0.0/16",
expectedIsAzureCNI: false,
},
}

Expand Down Expand Up @@ -3093,6 +3200,16 @@ func TestGetAddonFuncMap(t *testing.T) {
if ret[0].Interface() != c.expectedMode {
t.Errorf("expected funcMap invocation of GetMode to return %s, instead got %s", c.expectedMode, ret[0].Interface())
}
v = reflect.ValueOf(funcMap["GetClusterSubnet"])
ret = v.Call(make([]reflect.Value, 0))
if ret[0].Interface() != c.expectedGetClusterSubnet {
t.Errorf("expected funcMap invocation of GetClusterSubnet to return %s, instead got %s", c.expectedGetClusterSubnet, ret[0].Interface())
}
v = reflect.ValueOf(funcMap["IsAzureCNI"])
ret = v.Call(make([]reflect.Value, 0))
if ret[0].Interface() != c.expectedIsAzureCNI {
t.Errorf("expected funcMap invocation of IsAzureCNI to return %t, instead got %t", c.expectedIsAzureCNI, ret[0].Interface())
}
})
}
}
Expand Down
Loading