Webhooks and cert manager
This commit is contained in:
parent
1415aebc78
commit
eb855f1c12
4
Makefile
4
Makefile
@ -38,6 +38,10 @@ deploy: manifests
|
|||||||
cd config/manager && kustomize edit set image controller=${IMG}
|
cd config/manager && kustomize edit set image controller=${IMG}
|
||||||
kustomize build config/default | kubectl apply -f -
|
kustomize build config/default | kubectl apply -f -
|
||||||
|
|
||||||
|
undeploy: manifests
|
||||||
|
cd config/manager && kustomize edit set image controller=${IMG}
|
||||||
|
kustomize build config/default | kubectl delete -f -
|
||||||
|
|
||||||
# Generate manifests e.g. CRD, RBAC etc.
|
# Generate manifests e.g. CRD, RBAC etc.
|
||||||
manifests: controller-gen
|
manifests: controller-gen
|
||||||
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
|
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
|
||||||
|
|||||||
@ -26,9 +26,9 @@ import (
|
|||||||
type BackupSessionState string
|
type BackupSessionState string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
New BackupSessionState = "New"
|
|
||||||
Running BackupSessionState = "Running"
|
Running BackupSessionState = "Running"
|
||||||
Done BackupSessionState = "Done"
|
Success BackupSessionState = "Success"
|
||||||
|
Failure BackupSessionState = "Failure"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Ref struct {
|
type Ref struct {
|
||||||
@ -59,6 +59,7 @@ type BackupSessionStatus struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// +kubebuilder:object:root=true
|
// +kubebuilder:object:root=true
|
||||||
|
// +kubebuilder:subresource:status
|
||||||
|
|
||||||
// BackupSession is the Schema for the backupsessions API
|
// BackupSession is the Schema for the backupsessions API
|
||||||
type BackupSession struct {
|
type BackupSession struct {
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import (
|
|||||||
var backupsessionlog = logf.Log.WithName("backupsession-resource")
|
var backupsessionlog = logf.Log.WithName("backupsession-resource")
|
||||||
|
|
||||||
func (r *BackupSession) SetupWebhookWithManager(mgr ctrl.Manager) error {
|
func (r *BackupSession) SetupWebhookWithManager(mgr ctrl.Manager) error {
|
||||||
|
backupsessionlog.Info("setupWebhook", "name", r.Name)
|
||||||
return ctrl.NewWebhookManagedBy(mgr).
|
return ctrl.NewWebhookManagedBy(mgr).
|
||||||
For(r).
|
For(r).
|
||||||
Complete()
|
Complete()
|
||||||
@ -34,7 +35,7 @@ func (r *BackupSession) SetupWebhookWithManager(mgr ctrl.Manager) error {
|
|||||||
|
|
||||||
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
|
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
|
||||||
|
|
||||||
// +kubebuilder:webhook:path=/mutate-formol-desmojim-fr-desmojim-fr-v1alpha1-backupsession,mutating=true,failurePolicy=fail,groups=formol.desmojim.fr.desmojim.fr,resources=backupsessions,verbs=create;update,versions=v1alpha1,name=mbackupsession.kb.io
|
// +kubebuilder:webhook:path=/mutate-formol-desmojim-fr-v1alpha1-backupsession,mutating=true,failurePolicy=fail,groups=formol.desmojim.fr,resources=backupsessions,verbs=create;update,versions=v1alpha1,name=mbackupsession.kb.io
|
||||||
|
|
||||||
var _ webhook.Defaulter = &BackupSession{}
|
var _ webhook.Defaulter = &BackupSession{}
|
||||||
|
|
||||||
@ -43,11 +44,10 @@ func (r *BackupSession) Default() {
|
|||||||
backupsessionlog.Info("default", "name", r.Name)
|
backupsessionlog.Info("default", "name", r.Name)
|
||||||
|
|
||||||
// TODO(user): fill in your defaulting logic.
|
// TODO(user): fill in your defaulting logic.
|
||||||
r.Status.BackupSessionState = New
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
|
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
|
||||||
// +kubebuilder:webhook:verbs=create;update,path=/validate-formol-desmojim-fr-desmojim-fr-v1alpha1-backupsession,mutating=false,failurePolicy=fail,groups=formol.desmojim.fr.desmojim.fr,resources=backupsessions,versions=v1alpha1,name=vbackupsession.kb.io
|
// +kubebuilder:webhook:verbs=create;update,path=/validate-formol-desmojim-fr-v1alpha1-backupsession,mutating=false,failurePolicy=fail,groups=formol.desmojim.fr,resources=backupsessions,versions=v1alpha1,name=vbackupsession.kb.io
|
||||||
|
|
||||||
var _ webhook.Validator = &BackupSession{}
|
var _ webhook.Validator = &BackupSession{}
|
||||||
|
|
||||||
|
|||||||
@ -22,6 +22,7 @@ package v1alpha1
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -242,7 +243,8 @@ func (in *BackupSessionStatus) DeepCopyInto(out *BackupSessionStatus) {
|
|||||||
}
|
}
|
||||||
if in.Duration != nil {
|
if in.Duration != nil {
|
||||||
in, out := &in.Duration, &out.Duration
|
in, out := &in.Duration, &out.Duration
|
||||||
*out = (*in).DeepCopy()
|
*out = new(metav1.Duration)
|
||||||
|
**out = **in
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@ kind: CustomResourceDefinition
|
|||||||
metadata:
|
metadata:
|
||||||
name: backupsessions.formol.desmojim.fr
|
name: backupsessions.formol.desmojim.fr
|
||||||
spec:
|
spec:
|
||||||
|
preserveUnknownFields: false
|
||||||
conversion:
|
conversion:
|
||||||
strategy: Webhook
|
strategy: Webhook
|
||||||
webhookClientConfig:
|
webhookClientConfig:
|
||||||
|
|||||||
@ -18,9 +18,9 @@ bases:
|
|||||||
- ../manager
|
- ../manager
|
||||||
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
|
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
|
||||||
# crd/kustomization.yaml
|
# crd/kustomization.yaml
|
||||||
#- ../webhook
|
- ../webhook
|
||||||
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
|
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
|
||||||
#- ../certmanager
|
- ../certmanager
|
||||||
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
|
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
|
||||||
#- ../prometheus
|
#- ../prometheus
|
||||||
|
|
||||||
@ -32,39 +32,39 @@ patchesStrategicMerge:
|
|||||||
|
|
||||||
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
|
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
|
||||||
# crd/kustomization.yaml
|
# crd/kustomization.yaml
|
||||||
#- manager_webhook_patch.yaml
|
- manager_webhook_patch.yaml
|
||||||
|
|
||||||
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'.
|
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'.
|
||||||
# Uncomment 'CERTMANAGER' sections in crd/kustomization.yaml to enable the CA injection in the admission webhooks.
|
# Uncomment 'CERTMANAGER' sections in crd/kustomization.yaml to enable the CA injection in the admission webhooks.
|
||||||
# 'CERTMANAGER' needs to be enabled to use ca injection
|
# 'CERTMANAGER' needs to be enabled to use ca injection
|
||||||
#- webhookcainjection_patch.yaml
|
- webhookcainjection_patch.yaml
|
||||||
|
|
||||||
# the following config is for teaching kustomize how to do var substitution
|
# the following config is for teaching kustomize how to do var substitution
|
||||||
vars:
|
vars:
|
||||||
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
|
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
|
||||||
#- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
|
- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
|
||||||
# objref:
|
objref:
|
||||||
# kind: Certificate
|
kind: Certificate
|
||||||
# group: cert-manager.io
|
group: cert-manager.io
|
||||||
# version: v1alpha2
|
version: v1alpha2
|
||||||
# name: serving-cert # this name should match the one in certificate.yaml
|
name: serving-cert # this name should match the one in certificate.yaml
|
||||||
# fieldref:
|
fieldref:
|
||||||
# fieldpath: metadata.namespace
|
fieldpath: metadata.namespace
|
||||||
#- name: CERTIFICATE_NAME
|
- name: CERTIFICATE_NAME
|
||||||
# objref:
|
objref:
|
||||||
# kind: Certificate
|
kind: Certificate
|
||||||
# group: cert-manager.io
|
group: cert-manager.io
|
||||||
# version: v1alpha2
|
version: v1alpha2
|
||||||
# name: serving-cert # this name should match the one in certificate.yaml
|
name: serving-cert # this name should match the one in certificate.yaml
|
||||||
#- name: SERVICE_NAMESPACE # namespace of the service
|
- name: SERVICE_NAMESPACE # namespace of the service
|
||||||
# objref:
|
objref:
|
||||||
# kind: Service
|
kind: Service
|
||||||
# version: v1
|
version: v1
|
||||||
# name: webhook-service
|
name: webhook-service
|
||||||
# fieldref:
|
fieldref:
|
||||||
# fieldpath: metadata.namespace
|
fieldpath: metadata.namespace
|
||||||
#- name: SERVICE_NAME
|
- name: SERVICE_NAME
|
||||||
# objref:
|
objref:
|
||||||
# kind: Service
|
kind: Service
|
||||||
# version: v1
|
version: v1
|
||||||
# name: webhook-service
|
name: webhook-service
|
||||||
|
|||||||
@ -10,7 +10,7 @@ spec:
|
|||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: kube-rbac-proxy
|
- name: kube-rbac-proxy
|
||||||
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0
|
image: quay.io/brancz/kube-rbac-proxy:v0.8.0-arm
|
||||||
args:
|
args:
|
||||||
- "--secure-listen-address=0.0.0.0:8443"
|
- "--secure-listen-address=0.0.0.0:8443"
|
||||||
- "--upstream=http://127.0.0.1:8080/"
|
- "--upstream=http://127.0.0.1:8080/"
|
||||||
|
|||||||
@ -1,2 +1,8 @@
|
|||||||
resources:
|
resources:
|
||||||
- manager.yaml
|
- manager.yaml
|
||||||
|
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||||
|
kind: Kustomization
|
||||||
|
images:
|
||||||
|
- name: controller
|
||||||
|
newName: desmo999r/formolcontroller
|
||||||
|
newTag: latest
|
||||||
|
|||||||
@ -6,7 +6,7 @@ resources:
|
|||||||
# Comment the following 4 lines if you want to disable
|
# Comment the following 4 lines if you want to disable
|
||||||
# the auth proxy (https://github.com/brancz/kube-rbac-proxy)
|
# the auth proxy (https://github.com/brancz/kube-rbac-proxy)
|
||||||
# which protects your /metrics endpoint.
|
# which protects your /metrics endpoint.
|
||||||
- auth_proxy_service.yaml
|
#- auth_proxy_service.yaml
|
||||||
- auth_proxy_role.yaml
|
#- auth_proxy_role.yaml
|
||||||
- auth_proxy_role_binding.yaml
|
#- auth_proxy_role_binding.yaml
|
||||||
- auth_proxy_client_clusterrole.yaml
|
#- auth_proxy_client_clusterrole.yaml
|
||||||
|
|||||||
@ -40,6 +40,10 @@ type BackupConfigurationReconciler struct {
|
|||||||
|
|
||||||
// +kubebuilder:rbac:groups=formol.desmojim.fr,resources=backupconfigurations,verbs=get;list;watch;create;update;patch;delete
|
// +kubebuilder:rbac:groups=formol.desmojim.fr,resources=backupconfigurations,verbs=get;list;watch;create;update;patch;delete
|
||||||
// +kubebuilder:rbac:groups=formol.desmojim.fr,resources=backupconfigurations/status,verbs=get;update;patch
|
// +kubebuilder:rbac:groups=formol.desmojim.fr,resources=backupconfigurations/status,verbs=get;update;patch
|
||||||
|
// +kubebuilder:rbac:groups=formol.desmojim.fr,resources=repoes,verbs=get;list;watch
|
||||||
|
// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete
|
||||||
|
// +kubebuilder:rbac:groups=batch,resources=cronjobs,verbs=get;list;watch;create;update;patch;delete
|
||||||
|
// +kubebuilder:rbac:groups=batch,resources=cronjobs/status,verbs=get
|
||||||
|
|
||||||
func (r *BackupConfigurationReconciler) addSidecarContainer(backupConf *formolv1alpha1.BackupConfiguration) error {
|
func (r *BackupConfigurationReconciler) addSidecarContainer(backupConf *formolv1alpha1.BackupConfiguration) error {
|
||||||
log := r.Log.WithValues("Repository", backupConf.Spec.Repository.Name)
|
log := r.Log.WithValues("Repository", backupConf.Spec.Repository.Name)
|
||||||
|
|||||||
2
main.go
2
main.go
@ -82,10 +82,12 @@ func main() {
|
|||||||
setupLog.Error(err, "unable to create controller", "controller", "BackupSession")
|
setupLog.Error(err, "unable to create controller", "controller", "BackupSession")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
if os.Getenv("ENABLE_WEBHOOKS") != "false" {
|
||||||
if err = (&formolv1alpha1.BackupSession{}).SetupWebhookWithManager(mgr); err != nil {
|
if err = (&formolv1alpha1.BackupSession{}).SetupWebhookWithManager(mgr); err != nil {
|
||||||
setupLog.Error(err, "unable to create webhook", "webhook", "BackupSession")
|
setupLog.Error(err, "unable to create webhook", "webhook", "BackupSession")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// +kubebuilder:scaffold:builder
|
// +kubebuilder:scaffold:builder
|
||||||
|
|
||||||
setupLog.Info("starting manager")
|
setupLog.Info("starting manager")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user