Skip to content

Commit d150b75

Browse files
aleoliadamjensenbot
authored andcommitted
add global lables and annotations to liqo-created resources
1 parent 10ef308 commit d150b75

File tree

74 files changed

+459
-124
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+459
-124
lines changed

cmd/fabric/main.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,19 @@ import (
4242
"github.com/liqotech/liqo/pkg/gateway/concurrent"
4343
"github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/external-network/remapping"
4444
"github.com/liqotech/liqo/pkg/route"
45+
argsutils "github.com/liqotech/liqo/pkg/utils/args"
4546
flagsutils "github.com/liqotech/liqo/pkg/utils/flags"
4647
kernelversion "github.com/liqotech/liqo/pkg/utils/kernel/version"
4748
"github.com/liqotech/liqo/pkg/utils/mapper"
49+
"github.com/liqotech/liqo/pkg/utils/resource"
4850
"github.com/liqotech/liqo/pkg/utils/restcfg"
4951
)
5052

5153
var (
52-
options = fabric.NewOptions()
53-
scheme = runtime.NewScheme()
54+
options = fabric.NewOptions()
55+
scheme = runtime.NewScheme()
56+
globalLabels argsutils.StringMap
57+
globalAnnotations argsutils.StringMap
5458
)
5559

5660
func init() {
@@ -68,6 +72,10 @@ func main() {
6872
restcfg.InitFlags(cmd.Flags())
6973
fabric.InitFlags(cmd.Flags(), options)
7074

75+
// Register the flags for setting global labels and annotations
76+
cmd.Flags().Var(&globalLabels, "global-labels", "Global labels to be added to all created resources (key=value)")
77+
cmd.Flags().Var(&globalAnnotations, "global-annotations", "Global annotations to be added to all created resources (key=value)")
78+
7179
if err := fabric.MarkFlagsRequired(&cmd); err != nil {
7280
klog.Error(err)
7381
os.Exit(1)
@@ -92,6 +100,10 @@ func run(cmd *cobra.Command, _ []string) error {
92100
// Set controller-runtime logger.
93101
log.SetLogger(klog.NewKlogr())
94102

103+
// Initialize global labels from flag
104+
resource.SetGlobalLabels(globalLabels.StringMap)
105+
resource.SetGlobalAnnotations(globalAnnotations.StringMap)
106+
95107
// Get the rest config.
96108
cfg := config.GetConfigOrDie()
97109

cmd/gateway/main.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,20 @@ import (
4040
"github.com/liqotech/liqo/pkg/gateway/connection/conncheck"
4141
"github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/external-network/remapping"
4242
"github.com/liqotech/liqo/pkg/route"
43+
argsutils "github.com/liqotech/liqo/pkg/utils/args"
4344
flagsutils "github.com/liqotech/liqo/pkg/utils/flags"
4445
"github.com/liqotech/liqo/pkg/utils/kernel"
4546
kernelversion "github.com/liqotech/liqo/pkg/utils/kernel/version"
4647
"github.com/liqotech/liqo/pkg/utils/mapper"
48+
"github.com/liqotech/liqo/pkg/utils/resource"
4749
"github.com/liqotech/liqo/pkg/utils/restcfg"
4850
)
4951

5052
var (
51-
connoptions *connection.Options
52-
scheme = runtime.NewScheme()
53+
connoptions *connection.Options
54+
scheme = runtime.NewScheme()
55+
globalLabels argsutils.StringMap
56+
globalAnnotations argsutils.StringMap
5357
)
5458

5559
func init() {
@@ -83,6 +87,10 @@ func main() {
8387

8488
connection.InitFlags(cmd.Flags(), connoptions)
8589

90+
// Register the flags for setting global labels and annotations
91+
cmd.Flags().Var(&globalLabels, "global-labels", "Global labels to be added to all created resources (key=value)")
92+
cmd.Flags().Var(&globalAnnotations, "global-annotations", "Global annotations to be added to all created resources (key=value)")
93+
8694
if err := cmd.Execute(); err != nil {
8795
klog.Error(err)
8896
os.Exit(1)
@@ -112,6 +120,10 @@ func run(cmd *cobra.Command, _ []string) error {
112120
// Set controller-runtime logger.
113121
log.SetLogger(klog.NewKlogr())
114122

123+
// Initialize global labels from flag
124+
resource.SetGlobalLabels(globalLabels.StringMap)
125+
resource.SetGlobalAnnotations(globalAnnotations.StringMap)
126+
115127
// Get the rest config.
116128
cfg := config.GetConfigOrDie()
117129

cmd/liqo-controller-manager/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import (
6262
"github.com/liqotech/liqo/pkg/utils/indexer"
6363
ipamips "github.com/liqotech/liqo/pkg/utils/ipam/mapping"
6464
"github.com/liqotech/liqo/pkg/utils/mapper"
65+
"github.com/liqotech/liqo/pkg/utils/resource"
6566
"github.com/liqotech/liqo/pkg/utils/restcfg"
6667
)
6768

@@ -88,6 +89,8 @@ func main() {
8889
var defaultNodeResources argsutils.ResourceMap
8990
var gatewayServerResources argsutils.StringList
9091
var gatewayClientResources argsutils.StringList
92+
var globalLabels argsutils.StringMap
93+
var globalAnnotations argsutils.StringMap
9194
var apiServerAddressOverride string
9295
var caOverride string
9396
var trustedCA bool
@@ -149,6 +152,10 @@ func main() {
149152
pflag.Var(&ingressClasses, "ingress-classes", "List of ingress classes offered by the cluster. Example: \"nginx;default,traefik\"")
150153
pflag.Var(&loadBalancerClasses, "load-balancer-classes", "List of load balancer classes offered by the cluster. Example:\"metallb;default\"")
151154
pflag.Var(&defaultNodeResources, "default-node-resources", "Default resources assigned to the Virtual Node Pod")
155+
pflag.Var(&globalLabels, "global-labels",
156+
"The set of labels that will be added to all resources created by Liqo controllers")
157+
pflag.Var(&globalAnnotations, "global-annotations",
158+
"The set of annotations that will be added to all resources created by Liqo controllers")
152159

153160
// OFFLOADING MODULE
154161
// Storage Provisioner parameters
@@ -198,6 +205,10 @@ func main() {
198205
DynamicSharedInformerFactory: dynamicinformer.NewFilteredDynamicSharedInformerFactory(dynClient, 0, corev1.NamespaceAll, nil),
199206
}
200207

208+
// Initialize global labels from flag
209+
resource.SetGlobalLabels(globalLabels.StringMap)
210+
resource.SetGlobalAnnotations(globalAnnotations.StringMap)
211+
201212
// Create the main manager.
202213
mgr, err := ctrl.NewManager(config, ctrl.Options{
203214
MapperProvider: mapper.LiqoMapperProvider(scheme),

cmd/liqoctl/cmd/root.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343
"github.com/liqotech/liqo/pkg/liqoctl/rest/resourceslice"
4444
"github.com/liqotech/liqo/pkg/liqoctl/rest/tenant"
4545
"github.com/liqotech/liqo/pkg/liqoctl/rest/virtualnode"
46+
"github.com/liqotech/liqo/pkg/utils/resource"
4647
)
4748

4849
var liqoctl string
@@ -120,6 +121,10 @@ func NewRootCommand(ctx context.Context) *cobra.Command {
120121
// Add the flags regarding Kubernetes access options.
121122
f.AddFlags(cmd.PersistentFlags(), cmd.RegisterFlagCompletionFunc)
122123
cmd.PersistentFlags().BoolVar(&f.SkipConfirm, "skip-confirm", false, "Skip the confirmation prompt (suggested for automation)")
124+
cmd.PersistentFlags().StringToStringVar(&f.GlobalLabels, "global-labels", nil,
125+
"Global labels to be added to all created resources (key=value)")
126+
cmd.PersistentFlags().StringToStringVar(&f.GlobalAnnotations, "global-annotations", nil,
127+
"Global annotations to be added to all created resources (key=value)")
123128

124129
cmd.AddCommand(newInstallCommand(ctx, f))
125130
cmd.AddCommand(newUninstallCommand(ctx, f))
@@ -160,6 +165,8 @@ func WithTemplate(str string) string {
160165
func singleClusterPersistentPreRun(_ *cobra.Command, f *factory.Factory, opts ...factory.Options) {
161166
// Populate the factory fields based on the configured parameters.
162167
f.Printer.CheckErr(f.Initialize(opts...))
168+
resource.SetGlobalLabels(f.GlobalLabels)
169+
resource.SetGlobalAnnotations(f.GlobalAnnotations)
163170
}
164171

165172
// twoClustersPersistentPreRun initializes both the local and the remote factory.

deployments/liqo/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
| authentication.enabled | bool | `true` | Enable/Disable the authentication module. |
1414
| common.affinity | object | `{}` | Affinity for all liqo pods, excluding virtual kubelet. |
1515
| common.extraArgs | list | `[]` | Extra arguments for all liqo pods, excluding virtual kubelet. |
16+
| common.globalAnnotations | object | `{}` | Global annotations to be added to all resources created by Liqo controllers |
17+
| common.globalLabels | object | `{"liqo.io/managed":"true"}` | Global labels to be added to all resources created by Liqo controllers |
1618
| common.nodeSelector | object | `{}` | NodeSelector for all liqo pods, excluding virtual kubelet. |
1719
| common.tolerations | list | `[]` | Tolerations for all liqo pods, excluding virtual kubelet. |
1820
| controllerManager.config.defaultLimitsEnforcement | string | `"None"` | It enforces offerer-side that offloaded pods do not exceed offered limits. This feature is suggested to be enabled when consumer-side enforcement is not sufficient. It has the same tradeoffs of resource quotas (i.e, it requires all offloaded pods to have resource limits set). Possible values are: None, Soft, Hard. None: no enforcement is applied. Soft: request <= limit. Hard: request == limit. |

deployments/liqo/templates/liqo-controller-manager-deployment.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ spec:
5656
- --default-limits-enforcement={{ .Values.controllerManager.config.defaultLimitsEnforcement }}
5757
{{- $d := dict "commandName" "--default-node-resources" "dictionary" .Values.offloading.defaultNodeResources -}}
5858
{{- include "liqo.concatenateMap" $d | nindent 10 }}
59+
{{- if .Values.common.globalAnnotations }}
60+
{{- $d := dict "commandName" "--global-annotations" "dictionary" .Values.common.globalAnnotations -}}
61+
{{- include "liqo.concatenateMap" $d | nindent 10 }}
62+
{{- end }}
63+
{{- if .Values.common.globalLabels }}
64+
{{- $d := dict "commandName" "--global-labels" "dictionary" .Values.common.globalLabels -}}
65+
{{- include "liqo.concatenateMap" $d | nindent 10 }}
66+
{{- end }}
5967
{{- if .Values.authentication.awsConfig.accessKeyId }}
6068
- --aws-access-key-id=$(ACCESS_KEY_ID)
6169
{{- end }}

deployments/liqo/templates/liqo-fabric-daemonset.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ spec:
4949
- --disable-kernel-version-check
5050
{{- end }}
5151
- --enable-nft-monitor={{ .Values.networking.fabric.config.nftablesMonitor }}
52+
{{- if .Values.common.globalAnnotations }}
53+
{{- $d := dict "commandName" "--global-annotations" "dictionary" .Values.common.globalAnnotations -}}
54+
{{- include "liqo.concatenateMap" $d | nindent 10 }}
55+
{{- end }}
56+
{{- if .Values.common.globalLabels }}
57+
{{- $d := dict "commandName" "--global-labels" "dictionary" .Values.common.globalLabels -}}
58+
{{- include "liqo.concatenateMap" $d | nindent 10 }}
59+
{{- end }}
5260
{{- if .Values.common.extraArgs }}
5361
{{- toYaml .Values.common.extraArgs | nindent 10 }}
5462
{{- end }}

deployments/liqo/templates/liqo-wireguard-gateway-client-template.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ spec:
5151
- --mode=client
5252
- --container-name=gateway
5353
- --concurrent-containers-names=wireguard,geneve
54+
{{- if .Values.common.globalAnnotations }}
55+
{{- $d := dict "commandName" "--global-annotations" "dictionary" .Values.common.globalAnnotations -}}
56+
{{- include "liqo.concatenateMap" $d | nindent 16 }}
57+
{{- end }}
58+
{{- if .Values.common.globalLabels }}
59+
{{- $d := dict "commandName" "--global-labels" "dictionary" .Values.common.globalLabels -}}
60+
{{- include "liqo.concatenateMap" $d | nindent 16 }}
61+
{{- end }}
5462
{{- if .Values.metrics.enabled }}
5563
- --metrics-address=:8082
5664
{{- end }}

deployments/liqo/templates/liqo-wireguard-gateway-server-template-eks.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ spec:
7878
- --mode=server
7979
- --container-name=gateway
8080
- --concurrent-containers-names=wireguard,geneve
81+
{{- if .Values.common.globalAnnotations }}
82+
{{- $d := dict "commandName" "--global-annotations" "dictionary" .Values.common.globalAnnotations -}}
83+
{{- include "liqo.concatenateMap" $d | nindent 16 }}
84+
{{- end }}
85+
{{- if .Values.common.globalLabels }}
86+
{{- $d := dict "commandName" "--global-labels" "dictionary" .Values.common.globalLabels -}}
87+
{{- include "liqo.concatenateMap" $d | nindent 16 }}
88+
{{- end }}
8189
{{- if .Values.metrics.enabled }}
8290
- --metrics-address=:8082
8391
{{- end }}

deployments/liqo/templates/liqo-wireguard-gateway-server-template.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ spec:
7171
- --mode=server
7272
- --container-name=gateway
7373
- --concurrent-containers-names=wireguard,geneve
74+
{{- if .Values.common.globalAnnotations }}
75+
{{- $d := dict "commandName" "--global-annotations" "dictionary" .Values.common.globalAnnotations -}}
76+
{{- include "liqo.concatenateMap" $d | nindent 16 }}
77+
{{- end }}
78+
{{- if .Values.common.globalLabels }}
79+
{{- $d := dict "commandName" "--global-labels" "dictionary" .Values.common.globalLabels -}}
80+
{{- include "liqo.concatenateMap" $d | nindent 16 }}
81+
{{- end }}
7482
{{- if .Values.metrics.enabled }}
7583
- --metrics-address=:8084
7684
{{- end }}

0 commit comments

Comments
 (0)