Skip to content
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
16 changes: 12 additions & 4 deletions pkg/controller/template/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,14 +365,22 @@ func cloudProvider(cfg RenderConfig) (interface{}, error) {
// Process the {{cloudConfigFlag .}}
// If the CloudProviderConfig field is set and not empty, this
// returns the cloud conf flag for kubelet [1] pointing the kubelet to use
// /etc/kubernetes/cloud.conf for configuring the cloud provider.
// /etc/kubernetes/cloud.conf for configuring the cloud provider for select platforms.
// By default even if CloudProviderConfig fields is set, the kubelet will be configured to used for
// select platforms only.
//
// [1]: https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet/#options
func cloudConfigFlag(cfg RenderConfig) interface{} {
if len(cfg.CloudProviderConfig) > 0 {
return "--cloud-config=/etc/kubernetes/cloud.conf"
if len(cfg.CloudProviderConfig) == 0 {
return ""
}
flag := "--cloud-config=/etc/kubernetes/cloud.conf"
switch cfg.Platform {
case platformAzure, platformOpenstack:
return flag
default:
return ""
}
return ""
}

// existsDir returns true if path exists and is a directory, false if the path
Expand Down
51 changes: 51 additions & 0 deletions pkg/controller/template/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,57 @@ func TestCloudProvider(t *testing.T) {
}
}

func TestCloudConfigFlag(t *testing.T) {
dummyTemplate := []byte(`{{cloudConfigFlag .}}`)

cases := []struct {
platform string
content string
res string
}{{
platform: "aws",
content: "",
res: "",
}, {
platform: "azure",
content: "",
res: "",
}, {
platform: "aws",
content: `
[dummy-config]
option = a
`,
res: "",
}, {
platform: "azure",
content: `
[dummy-config]
option = a
`,
res: "--cloud-config=/etc/kubernetes/cloud.conf",
}}
for idx, c := range cases {
name := fmt.Sprintf("case #%d", idx)
t.Run(name, func(t *testing.T) {
config := &mcfgv1.ControllerConfig{
Spec: mcfgv1.ControllerConfigSpec{
Platform: c.platform,
CloudProviderConfig: c.content,
},
}
got, err := renderTemplate(RenderConfig{&config.Spec, `{"dummy":"dummy"}`}, name, dummyTemplate)
if err != nil {
t.Fatalf("expected nil error %v", err)
}

if string(got) != c.res {
t.Fatalf("mismatch got: %s want: %s", got, c.res)
}
})
}
}

func TestEtcdPeerCertDNSNames(t *testing.T) {
dummyTemplate := []byte(`{{etcdPeerCertDNSNames .}}`)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ contents: |
--client-ca-file=/etc/kubernetes/ca.crt \
--cloud-provider=vsphere \
--volume-plugin-dir=/etc/kubernetes/kubelet-plugins/volume/exec \
--cloud-config=/etc/kubernetes/cloud.conf \
\
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove the line entirely? same in the worker service below

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently this is status for kubelet service files in master, and it would require changing the templates to allow skipping this file. Would it be okay to take it as a follow up to update the template to do this for all platforms?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EDIT: also I want this PR's scope confined to changing the render function behavior

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no worries @abhinavdahiya

we can get this PR in and make whatever small changes as a followup.

--anonymous-auth=false \
--register-with-taints=node-role.kubernetes.io/master=:NoSchedule \

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contents: |
--volume-plugin-dir=/etc/kubernetes/kubelet-plugins/volume/exec \
--client-ca-file=/etc/kubernetes/ca.crt \
--cloud-provider=vsphere \
--cloud-config=/etc/kubernetes/cloud.conf \
\
--anonymous-auth=false \

Restart=always
Expand Down