-
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
2fde114
add application load balancer controller manager
efaf6a0
chore: add alb ingress controller docs run-it-locally how-to
079953a
Fix errors in stackit package
fischerman 04e5bf3
chore: add new Makefile build for alb ingress controller manager
38b50a0
Fix errors in ingress package (only non-test files)
fischerman 686f0a7
Add mocks for ALB and certificates API
fischerman 68811dc
Fix syntax errors in test in ingress package
fischerman 8076443
wip: Add alb-controller-manager deploy files
jamand b3fb5bd
Fix main.go
fischerman 746d072
Add mock generation for ALB and certificates API
fischerman 1426840
Fix linter issues
fischerman 127ab1d
Added waf config to change detection
175894e
Update docs for ALBCM
fischerman 8501597
Fix ALB unit tests
fischerman f1846ac
feat: read configuration from cloud config
128e706
chore: add a short description for setIPAddresses function
1cab4cd
Include envtest for controller tests
fischerman b40a2b7
Fix linter issues
fischerman b37a3a5
Remove license from code
fischerman 9b86598
chore: adjust issuer sample
c0385ae
chore: clarify isCertValid
3cc2fdf
chore: remove debug messages
37b5eef
fix: certificates not created because loadCerts skips all ingress tls…
9eea01b
fix: certificate deletion logic
d78e601
chore: adjsut externalIPAnnotation comment
c3b02c2
Adopt config to config structure
dergeberl 0edd42e
Move ReadConfig to config package
dergeberl e1f3f44
Remove unused webhook
dergeberl 24ced8a
Remove secure metrics
dergeberl 9266476
Enable LeaderElectionReleaseOnCancel
dergeberl ac251eb
Make linter happy
dergeberl 5c35199
Remove kubebuilder scaffold comments
dergeberl 40fd8e4
Remove crd import in envtest; remove getFirstFoundEnvTestBinaryDir as…
dergeberl 730655c
Remove dummy comment
dergeberl 870df27
Refactor SetupWithManager
dergeberl 7af9e33
WIP: Change how to build alb spec
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
141 changes: 141 additions & 0 deletions
141
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,141 @@ | ||
| 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(), | ||
| Recorder: mgr.GetEventRecorderFor("ingressclass-controller"), | ||
| 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