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

Commit

Permalink
Azure CNI networkmonitor addon (#3198)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfrancis authored Jun 13, 2018
1 parent 1e4f703 commit 254fcee
Show file tree
Hide file tree
Showing 13 changed files with 508 additions and 363 deletions.
48 changes: 48 additions & 0 deletions parts/k8s/addons/azure-cni-networkmonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: azure-cni-networkmonitor
namespace: kube-system
labels:
app: azure-cnms
addonmanager.kubernetes.io/mode: "EnsureExists"
spec:
selector:
matchLabels:
k8s-app: azure-cnms
template:
metadata:
labels:
k8s-app: azure-cnms
annotations:
scheduler.alpha.kubernetes.io/critical-pod: ''
spec:
tolerations:
- key: CriticalAddonsOnly
operator: Exists
containers:
- name: azure-cnms
image: <azureCNINetworkMonitorImage>
securityContext:
privileged: true
env:
- name: HOSTNAME
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
volumeMounts:
- name: ebtables-rule-repo
mountPath: /var/run
- name: log
mountPath: /var/log
hostNetwork: true
volumes:
- name: log
hostPath:
path: /var/log
type: Directory
- name: ebtables-rule-repo
hostPath:
path: /var/run/
type: Directory
1 change: 1 addition & 0 deletions parts/k8s/kubernetesagentcustomdata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ AGENT_ARTIFACTS_CONFIG_PLACEHOLDER
{{if IsAzureCNI}}
# SNAT outbound traffic from pods to destinations outside of VNET.
iptables -t nat -A POSTROUTING -m iprange ! --dst-range 168.63.129.16 -m addrtype ! --dst-type local ! -d {{WrapAsVariable "vnetCidr"}} -j MASQUERADE
sed -i "s|<azureCNINetworkMonitorImage>|{{WrapAsVariable "AzureCNINetworkMonitorImageURL"}}|g" "/etc/kubernetes/addons/azure-cni-networkmonitor.yaml"
{{end}}
{{if not EnablePodSecurityPolicy}}
sed -i "s|apparmor_parser|d|g" "/etc/systemd/system/kubelet.service"
Expand Down
1 change: 1 addition & 0 deletions parts/k8s/kubernetesmastercustomdata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ MASTER_ARTIFACTS_CONFIG_PLACEHOLDER
{{if IsAzureCNI}}
# SNAT outbound traffic from pods to destinations outside of VNET.
iptables -t nat -A POSTROUTING -m iprange ! --dst-range 168.63.129.16 -m addrtype ! --dst-type local ! -d {{WrapAsVariable "vnetCidr"}} -j MASQUERADE
sed -i "s|<azureCNINetworkMonitorImage>|{{WrapAsVariable "AzureCNINetworkMonitorImageURL"}}|g" "/etc/kubernetes/addons/azure-cni-networkmonitor.yaml"
{{end}}
sed -i "s|<kubernetesAddonManagerSpec>|{{WrapAsVariable "kubernetesAddonManagerSpec"}}|g" "/etc/kubernetes/manifests/kube-addon-manager.yaml"
sed -i "s|<kubernetesHyperkubeSpec>|{{WrapAsVariable "kubernetesHyperkubeSpec"}}|g" "/etc/kubernetes/manifests/kube-apiserver.yaml"
Expand Down
1 change: 1 addition & 0 deletions parts/k8s/kubernetesmastervars.t
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@

{{if IsAzureCNI}}
"allocateNodeCidrs": false,
"AzureCNINetworkMonitorImageURL": "[parameters('AzureCNINetworkMonitorImageURL')]",
{{else}}
"allocateNodeCidrs": true,
{{end}}
Expand Down
9 changes: 9 additions & 0 deletions parts/k8s/kubernetesparams.t
Original file line number Diff line number Diff line change
Expand Up @@ -914,3 +914,12 @@
}
}
{{end}}
{{if IsAzureCNI}}
,"AzureCNINetworkMonitorImageURL": {
"defaultValue": "",
"metadata": {
"description": "Azure CNI networkmonitor Image URL"
},
"type": "string"
}
{{end}}
5 changes: 5 additions & 0 deletions pkg/acsengine/addons.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ func kubernetesAddonSettingsInit(profile *api.Properties) []kubernetesFeatureSet
"omsagent-daemonset.yaml",
profile.OrchestratorProfile.IsContainerMonitoringEnabled(),
},
{
"azure-cni-networkmonitor.yaml",
"azure-cni-networkmonitor.yaml",
profile.OrchestratorProfile.IsAzureCNI(),
},
}
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/acsengine/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ const (
DefaultNVIDIADevicePluginAddonName = "nvidia-device-plugin"
// ContainerMonitoringAddonName is the name of the kubernetes Container Monitoring addon deployment
ContainerMonitoringAddonName = "container-monitoring"
// AzureCNINetworkMonitoringAddonName is the name of the Azure CNI networkmonitor addon
AzureCNINetworkMonitoringAddonName = "azure-cni-networkmonitor"
// DefaultKubernetesKubeletMaxPods is the max pods per kubelet
DefaultKubernetesKubeletMaxPods = 110
// DefaultMasterEtcdServerPort is the default etcd server port for Kubernetes master nodes
Expand Down
31 changes: 29 additions & 2 deletions pkg/acsengine/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var (
TillerImageBase: "gcrio.azureedge.net/kubernetes-helm/",
ACIConnectorImageBase: "microsoft/",
NVIDIAImageBase: "nvidia/",
AzureCNIImageBase: "containernetworking/",
EtcdDownloadURLBase: "https://acs-mirror.azureedge.net/github-coreos",
KubeBinariesSASURLBase: "https://acs-mirror.azureedge.net/wink8s/",
WindowsPackageSASURLBase: "https://acs-mirror.azureedge.net/wink8s/",
Expand Down Expand Up @@ -333,6 +334,16 @@ var (
},
},
}

// DefaultAzureCNINetworkMonitorAddonsConfig is the default Azure CNI networkmonitor Kubernetes addon Config
DefaultAzureCNINetworkMonitorAddonsConfig = api.KubernetesAddon{
Name: AzureCNINetworkMonitoringAddonName,
Containers: []api.KubernetesContainerSpec{
{
Name: AzureCNINetworkMonitoringAddonName,
},
},
}
)

// setPropertiesDefaults for the container Properties, returns true if certs are generated
Expand Down Expand Up @@ -405,8 +416,9 @@ func setOrchestratorDefaults(cs *api.ContainerService) {
DefaultMetricsServerAddonsConfig,
DefaultNVIDIADevicePluginAddonsConfig,
DefaultContainerMonitoringAddonsConfig,
DefaultAzureCNINetworkMonitorAddonsConfig,
}
enforceK8sVersionAddonOverrides(o.KubernetesConfig.Addons, o)
enforceK8sAddonOverrides(o.KubernetesConfig.Addons, o)
} else {
// For each addon, provide default configuration if user didn't provide its own config
t := getAddonsIndexByName(o.KubernetesConfig.Addons, DefaultTillerAddonName)
Expand Down Expand Up @@ -451,6 +463,11 @@ func setOrchestratorDefaults(cs *api.ContainerService) {
// Provide default acs-engine config for Container Monitoring
o.KubernetesConfig.Addons = append(o.KubernetesConfig.Addons, DefaultContainerMonitoringAddonsConfig)
}
aN := getAddonsIndexByName(o.KubernetesConfig.Addons, AzureCNINetworkMonitoringAddonName)
if aN < 0 {
// Provide default acs-engine config for Azure CNI containernetworking Device Plugin
o.KubernetesConfig.Addons = append(o.KubernetesConfig.Addons, DefaultAzureCNINetworkMonitorAddonsConfig)
}
}
if o.KubernetesConfig.KubernetesImageBase == "" {
o.KubernetesConfig.KubernetesImageBase = cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase
Expand Down Expand Up @@ -554,6 +571,10 @@ func setOrchestratorDefaults(cs *api.ContainerService) {
if a.OrchestratorProfile.KubernetesConfig.Addons[cm].IsEnabled(api.DefaultContainerMonitoringAddonEnabled) {
a.OrchestratorProfile.KubernetesConfig.Addons[cm] = assignDefaultAddonVals(a.OrchestratorProfile.KubernetesConfig.Addons[cm], DefaultContainerMonitoringAddonsConfig)
}
aN := getAddonsIndexByName(a.OrchestratorProfile.KubernetesConfig.Addons, AzureCNINetworkMonitoringAddonName)
if a.OrchestratorProfile.KubernetesConfig.Addons[aN].IsEnabled(a.OrchestratorProfile.IsAzureCNI()) {
a.OrchestratorProfile.KubernetesConfig.Addons[aN] = assignDefaultAddonVals(a.OrchestratorProfile.KubernetesConfig.Addons[aN], DefaultAzureCNINetworkMonitorAddonsConfig)
}

if o.KubernetesConfig.PrivateCluster == nil {
o.KubernetesConfig.PrivateCluster = &api.PrivateCluster{}
Expand Down Expand Up @@ -1075,15 +1096,21 @@ func mapToString(valueMap map[string]string) string {
return strings.TrimSuffix(buf.String(), ",")
}

func enforceK8sVersionAddonOverrides(addons []api.KubernetesAddon, o *api.OrchestratorProfile) {
func enforceK8sAddonOverrides(addons []api.KubernetesAddon, o *api.OrchestratorProfile) {
m := getAddonsIndexByName(o.KubernetesConfig.Addons, DefaultMetricsServerAddonName)
o.KubernetesConfig.Addons[m].Enabled = k8sVersionMetricsServerAddonEnabled(o)
aN := getAddonsIndexByName(o.KubernetesConfig.Addons, AzureCNINetworkMonitoringAddonName)
o.KubernetesConfig.Addons[aN].Enabled = azureCNINetworkMonitorAddonEnabled(o)
}

func k8sVersionMetricsServerAddonEnabled(o *api.OrchestratorProfile) *bool {
return helpers.PointerToBool(common.IsKubernetesVersionGe(o.OrchestratorVersion, "1.9.0"))
}

func azureCNINetworkMonitorAddonEnabled(o *api.OrchestratorProfile) *bool {
return helpers.PointerToBool(o.IsAzureCNI())
}

func generateEtcdEncryptionKey() string {
b := make([]byte, 32)
rand.Read(b)
Expand Down
24 changes: 24 additions & 0 deletions pkg/acsengine/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,31 @@ func TestSetComponentsNetworkDefaults(t *testing.T) {
}
}
}
}

func TestIsAzureCNINetworkmonitorAddon(t *testing.T) {
mockCS := getMockBaseContainerService("1.10.3")
properties := mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.MasterProfile.Count = 1
properties.OrchestratorProfile.KubernetesConfig.NetworkPlugin = "azure"
setOrchestratorDefaults(&mockCS)

i := getAddonsIndexByName(properties.OrchestratorProfile.KubernetesConfig.Addons, AzureCNINetworkMonitoringAddonName)
if !helpers.IsTrueBoolPointer(properties.OrchestratorProfile.KubernetesConfig.Addons[i].Enabled) {
t.Fatalf("Azure CNI network plugin configuration should add Azure CNI networkmonitor addon")
}
mockCS = getMockBaseContainerService("1.10.3")
properties = mockCS.Properties
properties.OrchestratorProfile.OrchestratorType = "Kubernetes"
properties.MasterProfile.Count = 1
properties.OrchestratorProfile.KubernetesConfig.NetworkPlugin = "kubenet"
setOrchestratorDefaults(&mockCS)

i = getAddonsIndexByName(properties.OrchestratorProfile.KubernetesConfig.Addons, AzureCNINetworkMonitoringAddonName)
if helpers.IsTrueBoolPointer(properties.OrchestratorProfile.KubernetesConfig.Addons[i].Enabled) {
t.Fatalf("Azure CNI networkmonitor addon should only be present in Azure CNI configurations")
}
}

func getMockAddon(name string) api.KubernetesAddon {
Expand Down
Loading

0 comments on commit 254fcee

Please sign in to comment.