Skip to content

Commit

Permalink
feat: cluster upgrade operations upgrade pause image (Azure#3689)
Browse files Browse the repository at this point in the history
  • Loading branch information
jadarsie authored and penggu committed Oct 28, 2020
1 parent 9739b2a commit 9e80328
Show file tree
Hide file tree
Showing 2 changed files with 221 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/api/defaults-kubelet.go
Expand Up @@ -138,6 +138,11 @@ func (cs *ContainerService) setKubeletConfig(isUpgrade bool) {

// If no user-configurable kubelet config values exists, use the defaults
setMissingKubeletValues(o.KubernetesConfig, defaultKubeletConfig)
if isUpgrade {
// if upgrade, force default "--pod-infra-container-image" value
o.KubernetesConfig.KubeletConfig["--pod-infra-container-image"] = defaultKubeletConfig["--pod-infra-container-image"]
}

addDefaultFeatureGates(o.KubernetesConfig.KubeletConfig, o.OrchestratorVersion, minVersionRotateCerts, "RotateKubeletServerCertificate=true")

// Override default cloud-provider?
Expand Down Expand Up @@ -178,8 +183,14 @@ func (cs *ContainerService) setKubeletConfig(isUpgrade bool) {
if cs.Properties.MasterProfile != nil {
if cs.Properties.MasterProfile.KubernetesConfig == nil {
cs.Properties.MasterProfile.KubernetesConfig = &KubernetesConfig{}
}
if cs.Properties.MasterProfile.KubernetesConfig.KubeletConfig == nil {
cs.Properties.MasterProfile.KubernetesConfig.KubeletConfig = make(map[string]string)
}
if isUpgrade {
// if upgrade, force default "--pod-infra-container-image" value
cs.Properties.MasterProfile.KubernetesConfig.KubeletConfig["--pod-infra-container-image"] = o.KubernetesConfig.KubeletConfig["--pod-infra-container-image"]
}
setMissingKubeletValues(cs.Properties.MasterProfile.KubernetesConfig, o.KubernetesConfig.KubeletConfig)
addDefaultFeatureGates(cs.Properties.MasterProfile.KubernetesConfig.KubeletConfig, o.OrchestratorVersion, "", "")

Expand Down Expand Up @@ -223,9 +234,16 @@ func (cs *ContainerService) setKubeletConfig(isUpgrade bool) {
for _, profile := range cs.Properties.AgentPoolProfiles {
if profile.KubernetesConfig == nil {
profile.KubernetesConfig = &KubernetesConfig{}
}
if profile.KubernetesConfig.KubeletConfig == nil {
profile.KubernetesConfig.KubeletConfig = make(map[string]string)
}

if isUpgrade {
// if upgrade, force default "--pod-infra-container-image" value
profile.KubernetesConfig.KubeletConfig["--pod-infra-container-image"] = o.KubernetesConfig.KubeletConfig["--pod-infra-container-image"]
}

if profile.IsWindows() {
for key, val := range staticWindowsKubeletConfig {
profile.KubernetesConfig.KubeletConfig[key] = val
Expand Down
203 changes: 203 additions & 0 deletions pkg/api/defaults-kubelet_test.go
Expand Up @@ -2180,8 +2180,211 @@ func TestSupportPodPidsLimitFeatureGateInAgentPool(t *testing.T) {
}
})
}
}

func TestInputOverridesDuringUpgrade(t *testing.T) {
defaultConfig := map[string]string{
"--pod-infra-container-image": pauseImageReference,
}

defaultWindowsConfig := map[string]string{
"--pod-infra-container-image": "kubletwin/pause",
}

inputConfig := map[string]string{
"--pod-infra-container-image": "input-pause",
}

cases := []struct {
name string
cs *ContainerService
isUpgrade bool
expectedKubeletConfig map[string]string
expectedWinKubeletConfig map[string]string
}{
{
name: "use default value if no input",
cs: &ContainerService{
Properties: &Properties{
OrchestratorProfile: &OrchestratorProfile{
OrchestratorType: Kubernetes,
OrchestratorVersion: "1.18.2",
KubernetesConfig: &KubernetesConfig{
KubeletConfig: map[string]string{},
},
},
MasterProfile: &MasterProfile{
KubernetesConfig: &KubernetesConfig{
KubeletConfig: map[string]string{},
},
},
AgentPoolProfiles: []*AgentPoolProfile{
{
OSType: "Linux",
KubernetesConfig: &KubernetesConfig{
KubeletConfig: map[string]string{},
},
},
{
OSType: "Windows",
KubernetesConfig: &KubernetesConfig{
KubeletConfig: map[string]string{},
},
},
},
},
},
isUpgrade: false,
expectedKubeletConfig: defaultConfig,
expectedWinKubeletConfig: defaultWindowsConfig,
},
{
name: "use input if not upgrade",
cs: &ContainerService{
Properties: &Properties{
OrchestratorProfile: &OrchestratorProfile{
OrchestratorType: Kubernetes,
OrchestratorVersion: "1.18.2",
KubernetesConfig: &KubernetesConfig{
KubeletConfig: map[string]string{
"--pod-infra-container-image": "input-pause",
},
},
},
MasterProfile: &MasterProfile{
KubernetesConfig: &KubernetesConfig{
KubeletConfig: map[string]string{
"--pod-infra-container-image": "input-pause",
},
},
},
AgentPoolProfiles: []*AgentPoolProfile{
{
OSType: "Linux",
KubernetesConfig: &KubernetesConfig{
KubeletConfig: map[string]string{
"--pod-infra-container-image": "input-pause",
},
},
},
{
OSType: "Windows",
KubernetesConfig: &KubernetesConfig{
KubeletConfig: map[string]string{},
},
},
},
},
},
isUpgrade: false,
expectedKubeletConfig: inputConfig,
// --pod-infra-container-image is static for windows nodes
expectedWinKubeletConfig: defaultWindowsConfig,
},
{
name: "override input if upgrade",
cs: &ContainerService{
Properties: &Properties{
OrchestratorProfile: &OrchestratorProfile{
OrchestratorType: Kubernetes,
OrchestratorVersion: "1.18.2",
KubernetesConfig: &KubernetesConfig{
KubeletConfig: map[string]string{
"--pod-infra-container-image": "input-pause",
},
},
},
MasterProfile: &MasterProfile{
KubernetesConfig: &KubernetesConfig{
KubeletConfig: map[string]string{
"--pod-infra-container-image": "input-pause",
},
},
},
AgentPoolProfiles: []*AgentPoolProfile{
{
OSType: "Linux",
KubernetesConfig: &KubernetesConfig{
KubeletConfig: map[string]string{
"--pod-infra-container-image": "input-pause",
},
},
},
{
OSType: "Windows",
KubernetesConfig: &KubernetesConfig{
KubeletConfig: map[string]string{},
},
},
},
},
},
isUpgrade: true,
expectedKubeletConfig: defaultConfig,
expectedWinKubeletConfig: defaultWindowsConfig,
},
{
name: "override input if no input and upgrade",
cs: &ContainerService{
Properties: &Properties{
OrchestratorProfile: &OrchestratorProfile{
OrchestratorType: Kubernetes,
OrchestratorVersion: "1.18.2",
KubernetesConfig: &KubernetesConfig{
KubeletConfig: map[string]string{},
},
},
MasterProfile: &MasterProfile{
KubernetesConfig: &KubernetesConfig{
KubeletConfig: map[string]string{},
},
},
AgentPoolProfiles: []*AgentPoolProfile{
{
OSType: "Linux",
KubernetesConfig: &KubernetesConfig{
KubeletConfig: map[string]string{},
},
},
{
OSType: "Windows",
KubernetesConfig: &KubernetesConfig{
KubeletConfig: map[string]string{},
},
},
},
},
},
isUpgrade: true,
expectedKubeletConfig: defaultConfig,
expectedWinKubeletConfig: defaultWindowsConfig,
},
}

assert := func(profile string, expected, actual map[string]string, t *testing.T) {
for ek, ev := range expected {
av, ok := actual[ek]
if !ok {
t.Fatalf("%s missing expected config %s", profile, ek)
}
if av != ev {
t.Fatalf("%s expected config %s to equal %s, got %s", profile, ek, ev, av)
}
}
}

for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
c.cs.setKubeletConfig(c.isUpgrade)
assert("OrchestratorProfile", c.expectedKubeletConfig, c.cs.Properties.OrchestratorProfile.KubernetesConfig.KubeletConfig, t)
assert("MasterProfile", c.expectedKubeletConfig, c.cs.Properties.MasterProfile.KubernetesConfig.KubeletConfig, t)
assert("Linux AgentPoolProfile", c.expectedKubeletConfig, c.cs.Properties.AgentPoolProfiles[0].KubernetesConfig.KubeletConfig, t)
assert("Windows AgentPoolProfile", c.expectedWinKubeletConfig, c.cs.Properties.AgentPoolProfiles[1].KubernetesConfig.KubeletConfig, t)
})
}
}

func TestReadOnlyPort(t *testing.T) {
cases := []struct {
name string
Expand Down

0 comments on commit 9e80328

Please sign in to comment.