Skip to content

Commit

Permalink
Uplift to kubebuilder v3
Browse files Browse the repository at this point in the history
  • Loading branch information
kashifest committed Nov 16, 2021
1 parent c22cb7b commit 6e8d670
Show file tree
Hide file tree
Showing 29 changed files with 218 additions and 87 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore all files which are not go type
!**/*.go
!**/*.mod
!**/*.sum
41 changes: 36 additions & 5 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,16 +1,47 @@
domain: metal3.io
layout:
- go.kubebuilder.io/v3
multigroup: true
projectName: baremetal-operator
repo: github.com/metal3-io/baremetal-operator
resources:
- group: metal3.io
- api:
crdVersion: v1
namespaced: true
controller: true
domain: metal3.io
group: metal3.io
kind: BareMetalHost
path: github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1
version: v1alpha1
- group: metal3.io
webhooks:
validation: true
webhookVersion: v1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: metal3.io
group: metal3.io
kind: HostFirmwareSettings
path: github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1
version: v1alpha1
- group: metal3.io
- api:
crdVersion: v1
namespaced: true
controller: true
domain: metal3.io
group: metal3.io
kind: FirmwareSchema
path: github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1
version: v1alpha1
- group: metal3.io
- api:
crdVersion: v1
namespaced: true
controller: true
domain: metal3.io
group: metal3.io
kind: PreprovisioningImage
path: github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1
version: v1alpha1
version: "2"
version: "3"
1 change: 0 additions & 1 deletion apis/metal3.io/v1alpha1/baremetalhost_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down
5 changes: 2 additions & 3 deletions apis/metal3.io/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand All @@ -15,8 +14,8 @@ limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the metal3.io v1alpha1 API group
// +kubebuilder:object:generate=true
// +groupName=metal3.io
//+kubebuilder:object:generate=true
//+groupName=metal3.io
package v1alpha1

import (
Expand Down
6 changes: 3 additions & 3 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resources:
- bases/metal3.io_hostfirmwaresettings.yaml
- bases/metal3.io_firmwareschemas.yaml
- bases/metal3.io_preprovisioningimages.yaml
# +kubebuilder:scaffold:crdkustomizeresource
#+kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
Expand All @@ -15,15 +15,15 @@ patchesStrategicMerge:
#- patches/webhook_in_hostfirmwaresettings.yaml
#- patches/webhook_in_firmwareschemas.yaml
#- patches/webhook_in_preprovisioningimages.yaml
# +kubebuilder:scaffold:crdkustomizewebhookpatch
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
- patches/cainjection_in_baremetalhosts.yaml
#- patches/cainjection_in_hostfirmwaresettings.yaml
#- patches/cainjection_in_firmwareschemas.yaml
#- patches/cainjection_in_preprovisioningimages.yaml
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
configurations:
Expand Down
6 changes: 4 additions & 2 deletions config/crd/kustomizeconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ nameReference:
version: v1
fieldSpecs:
- kind: CustomResourceDefinition
version: v1
group: apiextensions.k8s.io
path: spec/conversion/webhookClientConfig/service/name
path: spec/conversion/webhook/clientConfig/service/name

namespace:
- kind: CustomResourceDefinition
version: v1
group: apiextensions.k8s.io
path: spec/conversion/webhookClientConfig/service/namespace
path: spec/conversion/webhook/clientConfig/service/namespace
create: false

varReference:
Expand Down
1 change: 0 additions & 1 deletion config/crd/patches/cainjection_in_baremetalhosts.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# The following patch adds a directive for certmanager to inject CA into the CRD
# CRD conversion requires k8s 1.13 or later.
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
Expand Down
20 changes: 10 additions & 10 deletions config/crd/patches/webhook_in_baremetalhosts.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# The following patch enables conversion webhook for CRD
# CRD conversion requires k8s 1.13 or later.
# The following patch enables a conversion webhook for the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: baremetalhosts.metal3.io
spec:
conversion:
strategy: Webhook
webhookClientConfig:
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
caBundle: Cg==
service:
namespace: system
name: webhook-service
path: /convert
webhook:
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
caBundle: Cg==
conversionReviewVersions:
- v1
17 changes: 9 additions & 8 deletions config/crd/patches/webhook_in_firmwareschemas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ metadata:
spec:
conversion:
strategy: Webhook
webhookClientConfig:
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
caBundle: Cg==
service:
namespace: system
name: webhook-service
path: /convert
webhook:
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
caBundle: Cg==
conversionReviewVersions:
- v1
18 changes: 10 additions & 8 deletions config/crd/patches/webhook_in_hostfirmwaresettings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ metadata:
spec:
conversion:
strategy: Webhook
webhookClientConfig:
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
caBundle: Cg==
service:
namespace: system
name: webhook-service
path: /convert
webhook:
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
caBundle: Cg==
conversionReviewVersions:
- v1

17 changes: 9 additions & 8 deletions config/crd/patches/webhook_in_preprovisioningimages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ metadata:
spec:
conversion:
strategy: Webhook
webhookClientConfig:
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
caBundle: Cg==
service:
namespace: system
name: webhook-service
path: /convert
webhook:
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
caBundle: Cg==
conversionReviewVersions:
- v1
16 changes: 10 additions & 6 deletions config/default/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,25 @@ bases:
- ../crd
- ../rbac
- ../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
- ../webhook
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
- ../certmanager
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
#- ../prometheus

patchesStrategicMerge:
# Protect the /metrics endpoint by putting it behind auth.
# If you want your controller-manager to expose the /metrics
# endpoint w/o any authn/z, please comment the following line.
# Protect the /metrics endpoint by putting it behind auth.
# If you want your controller-manager to expose the /metrics
# endpoint w/o any authn/z, please comment the following line.
- manager_auth_proxy_patch.yaml

# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# Mount the controller config file for loading manager configurations
# through a ComponentConfig type
#- manager_config_patch.yaml

# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
- manager_webhook_patch.yaml

Expand Down
2 changes: 1 addition & 1 deletion config/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This patch inject a sidecar container which is a HTTP proxy for the
# This patch inject a sidecar container which is a HTTP proxy for the
# controller manager, it performs RBAC authorization against the Kubernetes API using SubjectAccessReviews.
apiVersion: apps/v1
kind: Deployment
Expand Down
20 changes: 20 additions & 0 deletions config/default/manager_config_patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
spec:
template:
spec:
containers:
- name: manager
args:
- "--config=controller_manager_config.yaml"
volumeMounts:
- name: manager-config
mountPath: /controller_manager_config.yaml
subPath: controller_manager_config.yaml
volumes:
- name: manager-config
configMap:
name: manager-config
11 changes: 11 additions & 0 deletions config/manager/controller_manager_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: controller-runtime.sigs.k8s.io/v1alpha1
kind: ControllerManagerConfig
health:
healthProbeBindAddress: :9440
metrics:
bindAddress: 127.0.0.1:8085
webhook:
port: 9443
leaderElection:
leaderElect: true
resourceName: a9498140.metal3.io
8 changes: 8 additions & 0 deletions config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
resources:
- manager.yaml

generatorOptions:
disableNameSuffixHash: true

configMapGenerator:
- name: manager-config
files:
- controller_manager_config.yaml
17 changes: 10 additions & 7 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,19 @@ spec:
- configMapRef:
name: ironic
name: manager
readinessProbe:
securityContext:
allowPrivilegeEscalation: false
livenessProbe:
httpGet:
path: /healthz
port: 9440
initialDelaySeconds: 3
periodSeconds: 3
livenessProbe:
initialDelaySeconds: 15
periodSeconds: 20
readinessProbe:
httpGet:
path: /healthz
path: /readyz
port: 9440
initialDelaySeconds: 10
periodSeconds: 3
initialDelaySeconds: 5
periodSeconds: 10
serviceAccountName: controller-manager
terminationGracePeriodSeconds: 10
4 changes: 4 additions & 0 deletions config/prometheus/monitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ spec:
endpoints:
- path: /metrics
port: https
scheme: https
bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
tlsConfig:
insecureSkipVerify: true
selector:
matchLabels:
control-plane: controller-manager
6 changes: 4 additions & 2 deletions config/rbac/auth_proxy_client_clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ kind: ClusterRole
metadata:
name: metrics-reader
rules:
- nonResourceURLs: ["/metrics"]
verbs: ["get"]
- nonResourceURLs:
- "/metrics"
verbs:
- get
12 changes: 8 additions & 4 deletions config/rbac/auth_proxy_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ kind: ClusterRole
metadata:
name: proxy-role
rules:
- apiGroups: ["authentication.k8s.io"]
- apiGroups:
- authentication.k8s.io
resources:
- tokenreviews
verbs: ["create"]
- apiGroups: ["authorization.k8s.io"]
verbs:
- create
- apiGroups:
- authorization.k8s.io
resources:
- subjectaccessreviews
verbs: ["create"]
verbs:
- create
2 changes: 1 addition & 1 deletion config/rbac/auth_proxy_role_binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ roleRef:
name: proxy-role
subjects:
- kind: ServiceAccount
name: default
name: controller-manager
namespace: system
6 changes: 6 additions & 0 deletions config/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
resources:
# All RBAC will be applied under this service account in
# the deployment namespace. You may comment out this resource
# if your manager will use a service account that exists at
# runtime. Be sure to update RoleBinding and ClusterRoleBinding
# subjects if changing service account names.
- service_account.yaml
- role.yaml
- role_binding.yaml
- leader_election_role.yaml
Expand Down
Loading

0 comments on commit 6e8d670

Please sign in to comment.