Skip to content

Commit 43f52bc

Browse files
committed
Added new node-labels cmd flag
1 parent 7d40485 commit 43f52bc

File tree

2 files changed

+38
-0
lines changed
  • cmd/vsphere-cloud-controller-manager
  • pkg/cloudprovider/vsphere/options

2 files changed

+38
-0
lines changed

cmd/vsphere-cloud-controller-manager/main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ import (
3030
"syscall"
3131
"time"
3232

33+
apivalidation "k8s.io/apimachinery/pkg/util/validation"
3334
cloudprovider "k8s.io/cloud-provider"
3435
"k8s.io/cloud-provider-vsphere/pkg/cloudprovider/vsphere"
3536
"k8s.io/cloud-provider-vsphere/pkg/cloudprovider/vsphere/loadbalancer"
37+
voptions "k8s.io/cloud-provider-vsphere/pkg/cloudprovider/vsphere/options"
3638
"k8s.io/cloud-provider-vsphere/pkg/cloudprovider/vsphereparavirtual"
3739
pvconfig "k8s.io/cloud-provider-vsphere/pkg/cloudprovider/vsphereparavirtual/config"
3840
"k8s.io/cloud-provider/app"
@@ -98,6 +100,8 @@ func main() {
98100
globalflag.Register(namedFlagSets.FlagSet("generic"), "is-legacy-paravirtual")
99101
}
100102

103+
voptions.AddFlags(namedFlagSets.FlagSet("cloud-node-controller"))
104+
101105
for _, f := range namedFlagSets.FlagSets {
102106
fs.AddFlagSet(f)
103107
}
@@ -158,6 +162,14 @@ func main() {
158162
verflag.PrintAndExitIfRequested()
159163
cliflag.PrintFlags(cmd.Flags())
160164

165+
// Validate --node-labels keys follow Kubernetes label key formatting
166+
for key := range vsphere.AdditionalLabels {
167+
errList := apivalidation.IsQualifiedName(key)
168+
if len(errList) > 0 {
169+
klog.Fatalf("invalid --node-labels key %q: %s", key, strings.Join(errList, "; "))
170+
}
171+
}
172+
161173
c, err := ccmOptions.Config(app.ControllerNames(app.DefaultInitFuncConstructors), app.ControllersDisabledByDefault.List(), names.CCMControllerAliases(), app.AllWebhooks, app.DisabledByDefaultWebhooks)
162174
if err != nil {
163175
// explicitly ignore the error by Fprintf, exiting anyway
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package options
15+
16+
import (
17+
"github.com/spf13/pflag"
18+
"k8s.io/cloud-provider-vsphere/pkg/cloudprovider/vsphere"
19+
)
20+
21+
// AddFlags add the additional flags for the controller
22+
func AddFlags(fs *pflag.FlagSet) {
23+
fs.StringToStringVar(&vsphere.AdditionalLabels, "node-labels", nil,
24+
"Additional labels to add to vSphere nodes during registration. Each key must follow kubernetes label format.\n"+
25+
"Example: --node-labels=node.foo.bar=vsphere,foo.bar/mapi=")
26+
}

0 commit comments

Comments
 (0)