Skip to content

Commit

Permalink
Merge pull request #31 from damsien/main
Browse files Browse the repository at this point in the history
  • Loading branch information
damsien authored Dec 9, 2024
2 parents b4a6477 + 60335e1 commit 7f756db
Show file tree
Hide file tree
Showing 26 changed files with 668 additions and 210 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,6 @@ jobs:
sudo apt-get install -y make
- name: Run tests
run: make test-e2e
run: |
make kustomize
make test-e2e
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN go mod download
# Copy the go source
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/controller/ internal/controller/
COPY internal/ internal/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ build: manifests generate fmt vet ## Build manager binary.

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
export MANAGER_NAMESPACE=operator-system DYNAMIC_WEBHOOK_NAME=remotesyncer.syngit.io DEV=true && go run ./cmd/main.go
export MANAGER_NAMESPACE=operator-system DYNAMIC_WEBHOOK_NAME=remotesyncer.syngit.io DEV=true && go run cmd/main.go

# If you wish to build the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
Expand Down Expand Up @@ -221,6 +221,7 @@ kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
$(KUSTOMIZE): $(LOCALBIN)
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))


.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
Expand Down
2 changes: 2 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ resources:
version: v1beta2
webhooks:
conversion: true
validation: true
webhookVersion: v1
- api:
crdVersion: v1
Expand All @@ -201,5 +202,6 @@ resources:
version: v1beta2
webhooks:
conversion: true
validation: true
webhookVersion: v1
version: "3"
33 changes: 0 additions & 33 deletions api/v1beta2/remotesyncer_webhook_test.go

This file was deleted.

64 changes: 0 additions & 64 deletions api/v1beta2/remoteuser_webhook.go

This file was deleted.

33 changes: 0 additions & 33 deletions api/v1beta2/remoteuser_webhook_test.go

This file was deleted.

33 changes: 0 additions & 33 deletions api/v1beta2/remoteuserbinding_webhook_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion api/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 12 additions & 9 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
syngitv1beta1 "syngit.io/syngit/api/v1beta1"
syngitv1beta2 "syngit.io/syngit/api/v1beta2"
"syngit.io/syngit/internal/controller"
webhooksyngitv1beta2 "syngit.io/syngit/internal/webhook/v1beta2"
//+kubebuilder:scaffold:imports
)

Expand Down Expand Up @@ -141,10 +142,6 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "RemoteUser")
os.Exit(1)
}
mgr.GetWebhookServer().Register("/syngit-v1beta2-remoteuser-association", &webhook.Admission{Handler: &controller.RemoteUserWebhookHandler{
Client: mgr.GetClient(),
Decoder: admission.NewDecoder(mgr.GetScheme()),
}})

if err = (&controller.RemoteUserBindingReconciler{
Client: mgr.GetClient(),
Expand All @@ -163,20 +160,26 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "RemoteSyncer")
os.Exit(1)
}
// nolint:goconst
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
if err = (&syngitv1beta2.RemoteUser{}).SetupWebhookWithManager(mgr); err != nil {
if err = webhooksyngitv1beta2.SetupRemoteUserWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "RemoteUser")
os.Exit(1)
}
if err = (&syngitv1beta2.RemoteUserBinding{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "RemoteUserBinding")
if err = webhooksyngitv1beta2.SetupRemoteSyncerWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "RemoteSyncer")
os.Exit(1)
}
if err = (&syngitv1beta2.RemoteSyncer{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "RemoteSyncer")
if err = webhooksyngitv1beta2.SetupRemoteUserBindingWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "RemoteUserBinding")
os.Exit(1)
}
}
mgr.GetWebhookServer().Register("/syngit-v1beta2-remoteuser-association", &webhook.Admission{Handler: &webhooksyngitv1beta2.RemoteUserWebhookHandler{
Client: mgr.GetClient(),
Decoder: admission.NewDecoder(mgr.GetScheme()),
}})

//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ patches:

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
# - path: patches/cainjection_in_remoteusers.yaml
# - path: patches/cainjection_in_remoteuserbindings.yaml
# - path: patches/cainjection_in_remotesyncers.yaml
#- path: patches/cainjection_in_remoteusers.yaml
#- path: patches/cainjection_in_remotesyncers.yaml
#- path: patches/cainjection_in_remoteuserbindings.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# [WEBHOOK] To enable webhook, uncomment the following section
Expand Down
26 changes: 26 additions & 0 deletions config/network-policy/allow-metrics-traffic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This NetworkPolicy allows ingress traffic
# with Pods running on namespaces labeled with 'metrics: enabled'. Only Pods on those
# namespaces are able to gathering data from the metrics endpoint.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
labels:
app.kubernetes.io/name: output-dir
app.kubernetes.io/managed-by: kustomize
name: allow-metrics-traffic
namespace: system
spec:
podSelector:
matchLabels:
control-plane: controller-manager
policyTypes:
- Ingress
ingress:
# This allows ingress traffic from any namespace with the label metrics: enabled
- from:
- namespaceSelector:
matchLabels:
metrics: enabled # Only from namespaces with this label
ports:
- port: 8443
protocol: TCP
26 changes: 26 additions & 0 deletions config/network-policy/allow-webhook-traffic copy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This NetworkPolicy allows ingress traffic to your webhook server running
# as part of the controller-manager from specific namespaces and pods. CR(s) which uses webhooks
# will only work when applied in namespaces labeled with 'webhook: enabled'
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
labels:
app.kubernetes.io/name: output-dir
app.kubernetes.io/managed-by: kustomize
name: allow-webhook-traffic
namespace: system
spec:
podSelector:
matchLabels:
control-plane: controller-manager
policyTypes:
- Ingress
ingress:
# This allows ingress traffic from any namespace with the label webhook: enabled
- from:
- namespaceSelector:
matchLabels:
webhook: enabled # Only from namespaces with this label
ports:
- port: 443
protocol: TCP
26 changes: 26 additions & 0 deletions config/network-policy/allow-webhook-traffic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This NetworkPolicy allows ingress traffic to your webhook server running
# as part of the controller-manager from specific namespaces and pods. CR(s) which uses webhooks
# will only work when applied in namespaces labeled with 'webhook: enabled'
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
labels:
app.kubernetes.io/name: syngit
app.kubernetes.io/managed-by: kustomize
name: allow-webhook-traffic
namespace: system
spec:
podSelector:
matchLabels:
control-plane: controller-manager
policyTypes:
- Ingress
ingress:
# This allows ingress traffic from any namespace with the label webhook: enabled
- from:
- namespaceSelector:
matchLabels:
webhook: enabled # Only from namespaces with this label
ports:
- port: 443
protocol: TCP
3 changes: 3 additions & 0 deletions config/network-policy/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resources:
- allow-webhook-traffic.yaml
- allow-metrics-traffic.yaml
4 changes: 2 additions & 2 deletions config/webhook/manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ webhooks:
namespace: system
path: /validate-syngit-syngit-io-v1beta2-remotesyncer
failurePolicy: Fail
name: vremotesyncer.v1beta2.syngit.io
name: vremotesyncer-v1beta2.kb.io
rules:
- apiGroups:
- syngit.syngit.io
Expand All @@ -32,7 +32,7 @@ webhooks:
namespace: system
path: /validate-syngit-syngit-io-v1beta2-remoteuser
failurePolicy: Fail
name: vremoteuser.v1beta2.syngit.io
name: vremoteuser-v1beta2.kb.io
rules:
- apiGroups:
- syngit.syngit.io
Expand Down
Loading

0 comments on commit 7f756db

Please sign in to comment.