Skip to content

Commit

Permalink
fix argocd install
Browse files Browse the repository at this point in the history
  • Loading branch information
aleoli committed Nov 5, 2024
1 parent 373dc94 commit 481a728
Show file tree
Hide file tree
Showing 14 changed files with 407 additions and 199 deletions.
39 changes: 39 additions & 0 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"k8s.io/klog/v2"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager"
Expand All @@ -52,6 +53,7 @@ import (
podwh "github.com/liqotech/liqo/pkg/webhooks/pod"
resourceslicewh "github.com/liqotech/liqo/pkg/webhooks/resourceslice"
routecfgwh "github.com/liqotech/liqo/pkg/webhooks/routeconfiguration"
"github.com/liqotech/liqo/pkg/webhooks/secretcontroller"
shadowpodswh "github.com/liqotech/liqo/pkg/webhooks/shadowpod"
virtualnodewh "github.com/liqotech/liqo/pkg/webhooks/virtualnode"
)
Expand All @@ -76,6 +78,7 @@ func main() {
metricsAddr := pflag.String("metrics-address", ":8080", "The address the metric endpoint binds to")
probeAddr := pflag.String("health-probe-address", ":8081", "The address the health probe endpoint binds to")
leaderElection := pflag.Bool("enable-leader-election", false, "Enable leader election for the webhook pod")
secretName := pflag.String("secret-name", "", "The name of the secret containing the webhook certificates")

// Global parameters
clusterIDFlags := argsutils.NewClusterIDFlags(true, nil)
Expand Down Expand Up @@ -103,6 +106,34 @@ func main() {

config := restcfg.SetRateLimiter(ctrl.GetConfigOrDie())

// create a client used for configuration
cl, err := client.New(config, client.Options{Scheme: scheme})
if err != nil {
klog.Error(err)
os.Exit(1)
}

// forge secret for the webhook
if *secretName != "" {
var secret corev1.Secret
if err := cl.Get(ctx, client.ObjectKey{Namespace: *liqoNamespace, Name: *secretName}, &secret); err != nil {
klog.Error(err)
os.Exit(1)
}

if err := secretcontroller.HandleSecret(ctx, cl, &secret); err != nil {
klog.Error(err)
os.Exit(1)
}

if err := cl.Update(ctx, &secret); err != nil {
klog.Error(err)
os.Exit(1)
}

klog.Info("webhook secret correctly enforced")
}

// Create the main manager.
mgr, err := ctrl.NewManager(config, ctrl.Options{
MapperProvider: mapper.LiqoMapperProvider(scheme),
Expand Down Expand Up @@ -169,6 +200,14 @@ func main() {
mgr.GetWebhookServer().Register("/mutate/firewallconfigurations", fwcfgwh.NewMutator())
mgr.GetWebhookServer().Register("/validate/routeconfigurations", routecfgwh.NewValidator(mgr.GetClient()))

// Register the secret controller
secretReconciler := secretcontroller.NewSecretReconciler(mgr.GetClient(), mgr.GetScheme(),
mgr.GetEventRecorderFor("secret-controller"))
if err := secretReconciler.SetupWithManager(mgr); err != nil {
klog.Errorf("Unable to set up the secret controller: %v", err)
os.Exit(1)
}

if leaderElection != nil && *leaderElection {
leaderelection.LabelerOnElection(ctx, mgr, &leaderelection.PodInfo{
PodName: os.Getenv("POD_NAME"),
Expand Down
22 changes: 22 additions & 0 deletions deployments/liqo/files/liqo-webhook-ClusterRole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ rules:
- patch
- update
- watch
- apiGroups:
- ""
resources:
- secrets
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- admissionregistration.k8s.io
resources:
- mutatingwebhookconfigurations
- validatingwebhookconfigurations
verbs:
- get
- list
- update
- watch
- apiGroups:
- apps
resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,6 @@ spec:
{{- end }}
{{- end }}
resources: {{- toYaml .Values.controllerManager.pod.resources | nindent 10 }}
volumeMounts:
- name: webhook-certs
mountPath: /tmp/k8s-webhook-server/serving-certs/
readOnly: true
ports:
- name: webhook
containerPort: {{ .Values.webhook.port }}
Expand All @@ -174,11 +170,6 @@ spec:
httpGet:
path: /readyz
port: healthz
volumes:
- name: webhook-certs
secret:
secretName: {{ include "liqo.prefixedName" $webhookConfig }}-certs
defaultMode: 420
{{- if ((.Values.common).nodeSelector) }}
nodeSelector:
{{- toYaml .Values.common.nodeSelector | nindent 8 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ spec:
{{- end }}
- --cluster-id=$(CLUSTER_ID)
- --liqo-namespace=$(POD_NAMESPACE)
- --secret-name={{ include "liqo.prefixedName" $webhookConfig }}-certs
- --podcidr={{ .Values.ipam.podCIDR }}
- --vk-options-default-template={{ .Release.Namespace }}/{{ printf "%s-default" $kubeletConfig.name }}
{{- if .Values.controllerManager.config.enableResourceEnforcement }}
Expand Down Expand Up @@ -83,10 +84,6 @@ spec:
- name: DEPLOYMENT_NAME
value: {{ include "liqo.prefixedName" $webhookConfig }}
resources: {{- toYaml .Values.webhook.pod.resources | nindent 10 }}
volumeMounts:
- name: webhook-certs
mountPath: /tmp/k8s-webhook-server/serving-certs/
readOnly: true
ports:
- name: webhook
containerPort: {{ .Values.webhook.port }}
Expand All @@ -101,11 +98,12 @@ spec:
httpGet:
path: /readyz
port: healthz
volumeMounts:
- name: webhook-certs
mountPath: /tmp/k8s-webhook-server
volumes:
- name: webhook-certs
secret:
secretName: {{ include "liqo.prefixedName" $webhookConfig }}-certs
defaultMode: 420
emptyDir: {}
{{- if ((.Values.common).nodeSelector) }}
nodeSelector:
{{- toYaml .Values.common.nodeSelector | nindent 8 }}
Expand Down

This file was deleted.

This file was deleted.

85 changes: 0 additions & 85 deletions deployments/liqo/templates/webhooks/job-patch/rbac.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ metadata:
name: {{ include "liqo.prefixedName" $webhookConfig }}
labels:
{{- include "liqo.labels" $webhookConfig | nindent 4 }}
liqo.io/webhook: "true"
webhooks:
- name: pod.mutate.liqo.io
admissionReviewVersions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ metadata:
name: {{ include "liqo.prefixedName" $webhookConfig }}
labels:
{{- include "liqo.labels" $webhookConfig | nindent 4 }}
liqo.io/webhook: "true"
webhooks:
- name: nsoff.validate.liqo.io
admissionReviewVersions:
Expand Down
12 changes: 12 additions & 0 deletions deployments/liqo/templates/webhooks/liqo-webhook-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- $webhookConfig := (merge (dict "name" "webhook" "module" "webhook") .) -}}

apiVersion: v1
kind: Secret
metadata:
name: {{ include "liqo.prefixedName" $webhookConfig }}-certs
labels:
{{- include "liqo.labels" $webhookConfig | nindent 4 }}
liqo.io/webhook: "true"
annotations:
liqo.io/webhook-service-name: {{ include "liqo.prefixedName" $webhookConfig }}
type: opaque
10 changes: 10 additions & 0 deletions pkg/consts/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,14 @@ const (
// IpamStorageResourceLabelValue is the constant representing
// the value of the label assigned to all IpamStorage resources.
IpamStorageResourceLabelValue = "true"

// WebhookResourceLabelKey is the constant representing
// the key of the label assigned to all Webhook resources.
WebhookResourceLabelKey = "liqo.io/webhook"
// WebhookResourceLabelValue is the constant representing
// the value of the label assigned to all Webhook resources.
WebhookResourceLabelValue = "true"
// WebhookServiceNameAnnotationKey is the constant representing
// the key of the annotation containing the Webhook service name.
WebhookServiceNameAnnotationKey = "liqo.io/webhook-service-name"
)
Loading

0 comments on commit 481a728

Please sign in to comment.