-
Notifications
You must be signed in to change notification settings - Fork 3
WIP: Add Application Load Balancer Controller Manager #879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kamilprzybyl
wants to merge
36
commits into
main
Choose a base branch
from
feat/kp/add-alb-ingress-controller
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
64b5f64
add application load balancer controller manager
d623425
chore: add alb ingress controller docs run-it-locally how-to
cbf5622
Fix errors in stackit package
fischerman d7971df
chore: add new Makefile build for alb ingress controller manager
05be587
Fix errors in ingress package (only non-test files)
fischerman 9440cac
Add mocks for ALB and certificates API
fischerman cd270f1
Fix syntax errors in test in ingress package
fischerman cf3d7ac
wip: Add alb-controller-manager deploy files
jamand bb40d21
Fix main.go
fischerman c18c393
Add mock generation for ALB and certificates API
fischerman 6bd4ba5
Fix linter issues
fischerman bd2bf6c
Added waf config to change detection
4302bb9
Update docs for ALBCM
fischerman 76f737e
Fix ALB unit tests
fischerman 5744c59
feat: read configuration from cloud config
a4c3eee
chore: add a short description for setIPAddresses function
76e1f49
Include envtest for controller tests
fischerman 1b1f8da
Undo temporary changes
fischerman 931b420
Fix linter issues
fischerman a19d91f
Remove license from code
fischerman 261c701
chore: adjust issuer sample
8eeb62c
chore: clarify isCertValid
f7d1a76
chore: remove debug messages
1ff73e6
fix: certificates not created because loadCerts skips all ingress tls…
838e4c5
fix: certificate deletion logic
9d6f767
chore: adjsut externalIPAnnotation comment
98c71c0
Adopt config to config structure
dergeberl e823347
Move ReadConfig to config package
dergeberl c66f776
Remove unused webhook
dergeberl 3ec8b81
Remove secure metrics
dergeberl f9fdf11
Enable LeaderElectionReleaseOnCancel
dergeberl d8cb339
Make linter happy
dergeberl 693873a
Remove kubebuilder scaffold comments
dergeberl f4ec638
Remove crd import in envtest; remove getFirstFoundEnvTestBinaryDir as…
dergeberl 85e6a10
Remove dummy comment
dergeberl 87dc2c6
Refactor SetupWithManager
dergeberl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
cmd/application-load-balancer-controller-manager/main.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "flag" | ||
| "os" | ||
|
|
||
| "github.com/stackitcloud/cloud-provider-stackit/pkg/alb/ingress" | ||
| albclient "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit" | ||
| stackitconfig "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/config" | ||
| sdkconfig "github.com/stackitcloud/stackit-sdk-go/core/config" | ||
| albsdk "github.com/stackitcloud/stackit-sdk-go/services/alb/v2api" | ||
| certsdk "github.com/stackitcloud/stackit-sdk-go/services/certificates/v2api" | ||
|
|
||
| "k8s.io/apimachinery/pkg/runtime" | ||
| utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
| clientgoscheme "k8s.io/client-go/kubernetes/scheme" | ||
| _ "k8s.io/client-go/plugin/pkg/client/auth" | ||
| ctrl "sigs.k8s.io/controller-runtime" | ||
| "sigs.k8s.io/controller-runtime/pkg/healthz" | ||
| "sigs.k8s.io/controller-runtime/pkg/log/zap" | ||
| metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" | ||
| ) | ||
|
|
||
| var ( | ||
| scheme = runtime.NewScheme() | ||
| setupLog = ctrl.Log.WithName("setup") | ||
| ) | ||
|
|
||
| func init() { | ||
| utilruntime.Must(clientgoscheme.AddToScheme(scheme)) | ||
| } | ||
|
|
||
| // nolint:funlen // TODO: Refactor into smaller functions. | ||
| func main() { | ||
| var metricsAddr string | ||
| var enableLeaderElection bool | ||
| var leaderElectionNamespace string | ||
| var leaderElectionID string | ||
| var probeAddr string | ||
| var cloudConfig string | ||
| flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to. "+ | ||
| "Use :8443 for HTTPS or :8080 for HTTP, or leave as 0 to disable the metrics service.") | ||
| flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.") | ||
| flag.BoolVar(&enableLeaderElection, "leader-elect", false, | ||
| "Enable leader election for controller manager. "+ | ||
| "Enabling this will ensure there is only one active controller manager.") | ||
| flag.StringVar(&leaderElectionNamespace, "leader-election-namespace", "default", "The namespace in which the leader "+ | ||
| "election resource will be created.") | ||
| flag.StringVar(&leaderElectionID, "leader-election-id", "d0fbe9c4.stackit.cloud", "The name of the resource that "+ | ||
| "leader election will use for holding the leader lock.") | ||
| flag.StringVar(&cloudConfig, "cloud-config", "cloud.yaml", "The path to the cloud config file.") | ||
| opts := zap.Options{ | ||
| Development: true, | ||
| } | ||
| opts.BindFlags(flag.CommandLine) | ||
| flag.Parse() | ||
|
|
||
| ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts))) | ||
|
|
||
| config, err := stackitconfig.ReadALBConfigFromFile(cloudConfig) | ||
| if err != nil { | ||
| setupLog.Error(err, "Failed to read cloud config") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ | ||
| Scheme: scheme, | ||
| Metrics: metricsserver.Options{ | ||
| BindAddress: metricsAddr, | ||
| }, | ||
| HealthProbeBindAddress: probeAddr, | ||
| LeaderElection: enableLeaderElection, | ||
| LeaderElectionID: leaderElectionID, | ||
| LeaderElectionNamespace: leaderElectionNamespace, | ||
| LeaderElectionReleaseOnCancel: true, | ||
| }) | ||
| if err != nil { | ||
| setupLog.Error(err, "unable to start manager") | ||
| os.Exit(1) | ||
| } | ||
| albOpts := []sdkconfig.ConfigurationOption{} | ||
| if config.Global.APIEndpoints.ApplicationLoadBalancerAPI != "" { | ||
| albOpts = append(albOpts, sdkconfig.WithEndpoint(config.Global.APIEndpoints.ApplicationLoadBalancerAPI)) | ||
| } | ||
|
|
||
| certOpts := []sdkconfig.ConfigurationOption{} | ||
| if config.Global.APIEndpoints.ApplicationLoadBalancerCertificateAPI != "" { | ||
| certOpts = append(certOpts, sdkconfig.WithEndpoint(config.Global.APIEndpoints.ApplicationLoadBalancerCertificateAPI)) | ||
| } | ||
|
|
||
| // Setup ALB API client | ||
| sdkClient, err := albsdk.NewAPIClient(albOpts...) | ||
| if err != nil { | ||
| setupLog.Error(err, "unable to create ALB SDK client", "controller", "IngressClass") | ||
| os.Exit(1) | ||
| } | ||
| albClient, err := albclient.NewApplicationLoadBalancerClient(sdkClient) | ||
| if err != nil { | ||
| setupLog.Error(err, "unable to create ALB client", "controller", "IngressClass") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| // Setup Certificates API client | ||
| certificateAPI, err := certsdk.NewAPIClient(certOpts...) | ||
| if err != nil { | ||
| setupLog.Error(err, "unable to create certificate SDK client", "controller", "IngressClass") | ||
| os.Exit(1) | ||
| } | ||
| certificateClient, err := albclient.NewCertClient(certificateAPI) | ||
| if err != nil { | ||
| setupLog.Error(err, "unable to create Certificates client", "controller", "IngressClass") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| if err = (&ingress.IngressClassReconciler{ | ||
| Client: mgr.GetClient(), | ||
| ALBClient: albClient, | ||
| CertificateClient: certificateClient, | ||
| Scheme: mgr.GetScheme(), | ||
| ALBConfig: config, | ||
| }).SetupWithManager(mgr); err != nil { | ||
| setupLog.Error(err, "unable to create controller", "controller", "IngressClass") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil { | ||
| setupLog.Error(err, "unable to set up health check") | ||
| os.Exit(1) | ||
| } | ||
| if err := mgr.AddReadyzCheck("readyz", healthz.Ping); err != nil { | ||
| setupLog.Error(err, "unable to set up ready check") | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| setupLog.Info("starting manager") | ||
| if err := mgr.Start(ctrl.SetupSignalHandler()); err != nil { | ||
| setupLog.Error(err, "problem running manager") | ||
| os.Exit(1) | ||
| } | ||
| } | ||
59 changes: 59 additions & 0 deletions
59
deploy/application-load-balancer-controller-manager/deployment.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| namespace: kube-system | ||
| name: stackit-application-load-balancer-contoller-manager | ||
| labels: | ||
| app: stackit-application-load-balancer-contoller-manager | ||
| spec: | ||
| replicas: 2 | ||
| strategy: | ||
| type: RollingUpdate | ||
| selector: | ||
| matchLabels: | ||
| app: stackit-application-load-balancer-contoller-manager | ||
| template: | ||
| metadata: | ||
| labels: | ||
| app: stackit-application-load-balancer-contoller-manager | ||
| spec: | ||
| serviceAccountName: stackit-application-load-balancer-contoller-manager | ||
| terminationGracePeriodSeconds: 30 | ||
| containers: | ||
| - name: stackit-application-load-balancer-contoller-manager | ||
| # TODO(jamand): Adapt image tag | ||
| image: ghcr.io/stackitcloud/cloud-provider-stackit/stackit-application-load-balancer-contoller-manager:XXX | ||
| args: | ||
| - "--authorization-always-allow-paths=/metrics" | ||
| - "--leader-elect=true" | ||
| - "--leader-elect-resource-name=stackit-application-load-balancer-contoller-manager" | ||
| - "--enable-http2" | ||
| - "--metrics-bind-address=8080" | ||
| - "--secureMetrics=false" | ||
| # TODO(jamand): Check webhook cert + enableHTTP2 flag | ||
| env: | ||
| - name: STACKIT_SERVICE_ACCOUNT_KEY_PATH | ||
| value: /etc/serviceaccount/sa_key.json | ||
| ports: | ||
| - containerPort: 8080 | ||
| hostPort: 8080 | ||
| name: metrics | ||
| protocol: TCP | ||
| - containerPort: 8081 | ||
| hostPort: 8081 | ||
| name: probe | ||
| protocol: TCP | ||
| resources: | ||
| limits: | ||
| cpu: "0.5" | ||
| memory: 500Mi | ||
| requests: | ||
| cpu: "0.1" | ||
| memory: 100Mi | ||
| volumeMounts: | ||
| - mountPath: /etc/serviceaccount | ||
| name: cloud-secret | ||
| volumes: | ||
| - name: cloud-secret | ||
| secret: | ||
| secretName: stackit-cloud-secret |
7 changes: 7 additions & 0 deletions
7
deploy/application-load-balancer-controller-manager/kustomization.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| apiVersion: kustomize.config.k8s.io/v1beta1 | ||
| kind: Kustomization | ||
|
|
||
| resources: | ||
| - deployment.yaml | ||
| - rbac.yaml | ||
|
|
60 changes: 60 additions & 0 deletions
60
deploy/application-load-balancer-controller-manager/rbac.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| apiVersion: v1 | ||
| kind: ServiceAccount | ||
| metadata: | ||
| namespace: kube-system | ||
| name: stackit-application-load-balancer-contoller-manager | ||
| --- | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| kind: ClusterRole | ||
| metadata: | ||
| name: stackit-application-load-balancer-contoller-manager | ||
| rules: | ||
| # TODO(jamand): Go through rules again | ||
| - apiGroups: | ||
| - "" | ||
| resources: | ||
| - events | ||
| verbs: | ||
| - create | ||
| - patch | ||
| - update | ||
| - apiGroups: | ||
| - "" | ||
| resources: | ||
| - nodes | ||
| verbs: | ||
| - list | ||
| - apiGroups: | ||
| - "networking.k8s.io" | ||
| resources: | ||
| - ingress | ||
| verbs: | ||
| - get | ||
| - apiGroups: | ||
| - "networking.k8s.io" | ||
| resources: | ||
| - ingress/status | ||
| verbs: | ||
| - patch | ||
| - apiGroups: | ||
| - "networking.k8s.io" | ||
| resources: | ||
| - ingressclass | ||
| verbs: | ||
| - list | ||
| - patch | ||
| - update | ||
| - watch | ||
| --- | ||
| kind: ClusterRoleBinding | ||
| apiVersion: rbac.authorization.k8s.io/v1 | ||
| metadata: | ||
| name: stackit-application-load-balancer-contoller-manager | ||
| roleRef: | ||
| apiGroup: rbac.authorization.k8s.io | ||
| kind: ClusterRole | ||
| name: stackit-application-load-balancer-contoller-manager | ||
| subjects: | ||
| - kind: ServiceAccount | ||
| name: stackit-application-load-balancer-contoller-manager | ||
| namespace: kube-system |
20 changes: 20 additions & 0 deletions
20
deploy/application-load-balancer-controller-manager/service.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| apiVersion: v1 | ||
| kind: Service | ||
| metadata: | ||
| labels: | ||
| app: stackit-application-load-balancer-contoller-manager | ||
| namespace: kube-system | ||
| name: stackit-application-load-balancer-contoller-manager | ||
| spec: | ||
| selector: | ||
| app: stackit-application-load-balancer-contoller-manager | ||
| ports: | ||
| - name: probe | ||
| port: 8081 | ||
| targetPort: probe | ||
| protocol: TCP | ||
| - name: metrics | ||
| port: 8080 | ||
| targetPort: metrics | ||
| protocol: TCP | ||
| type: ClusterIP |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move into a options struct