mirror of
https://github.com/YuzuZensai/netbird-kubernetes-operator.git
synced 2026-09-13 10:49:15 +00:00
Add feature to add default labels to all resources (#62)
Fixes #41 Thanks to @mhartmann-jaconi for the Helm changes in #42
This commit is contained in:
+22
@@ -22,6 +22,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
|
||||
// to ensure that exec-entrypoint and run can make use of them.
|
||||
@@ -74,6 +75,7 @@ func main() {
|
||||
clusterDNS string
|
||||
netbirdAPIKey string
|
||||
allowAutomaticPolicyCreation bool
|
||||
defaultLabels string
|
||||
)
|
||||
flag.StringVar(&managementURL, "netbird-management-url", "https://api.netbird.io", "Management service URL")
|
||||
flag.StringVar(&clientImage, "netbird-client-image", "netbirdio/netbird:latest", "Image for netbird client container")
|
||||
@@ -97,6 +99,12 @@ func main() {
|
||||
false,
|
||||
"Allow creating NBPolicy resources from annotations on Services",
|
||||
)
|
||||
flag.StringVar(
|
||||
&defaultLabels,
|
||||
"default-labels",
|
||||
"",
|
||||
"Default labels used for all resources, in format key=value,key=value",
|
||||
)
|
||||
|
||||
// Controller generic flags
|
||||
var (
|
||||
@@ -129,6 +137,17 @@ func main() {
|
||||
opts.BindFlags(flag.CommandLine)
|
||||
flag.Parse()
|
||||
|
||||
defaultLabelsMap := make(map[string]string)
|
||||
if defaultLabels != "" {
|
||||
for _, s := range strings.Split(defaultLabels, ",") {
|
||||
kv := strings.Split(s, "=")
|
||||
if len(kv) != 2 {
|
||||
panic(fmt.Errorf("invalid label format: %s", s))
|
||||
}
|
||||
defaultLabelsMap[kv[0]] = kv[1]
|
||||
}
|
||||
}
|
||||
|
||||
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
|
||||
|
||||
disableHTTP2 := func(c *tls.Config) {
|
||||
@@ -216,6 +235,7 @@ func main() {
|
||||
APIKey: netbirdAPIKey,
|
||||
ManagementURL: managementURL,
|
||||
NamespacedNetworks: namespacedNetworks,
|
||||
DefaultLabels: defaultLabelsMap,
|
||||
}).SetupWithManager(mgr); err != nil {
|
||||
setupLog.Error(err, "unable to create controller", "controller", "NBRoutingPeer")
|
||||
os.Exit(1)
|
||||
@@ -234,6 +254,7 @@ func main() {
|
||||
ClusterDNS: clusterDNS,
|
||||
NamespacedNetworks: namespacedNetworks,
|
||||
ControllerNamespace: controllerNamespace,
|
||||
DefaultLabels: defaultLabelsMap,
|
||||
}).SetupWithManager(mgr); err != nil {
|
||||
setupLog.Error(err, "unable to create controller", "controller", "Service")
|
||||
os.Exit(1)
|
||||
@@ -246,6 +267,7 @@ func main() {
|
||||
ManagementURL: managementURL,
|
||||
AllowAutomaticPolicyCreation: allowAutomaticPolicyCreation,
|
||||
ClusterName: clusterName,
|
||||
DefaultLabels: defaultLabelsMap,
|
||||
}).SetupWithManager(mgr); err != nil {
|
||||
setupLog.Error(err, "unable to create controller", "controller", "NBResource")
|
||||
os.Exit(1)
|
||||
|
||||
Reference in New Issue
Block a user