Skip to content

Commit fddb578

Browse files
committed
Add BothInstallerConfig resource
1 parent 2197a2a commit fddb578

14 files changed

+411
-0
lines changed

PROJECT

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,12 @@ resources:
1515
kind: BothInstallerConfigTemplate
1616
path: github.com/miscord-dev/cluster-api-byoh-both/api/v1alpha1
1717
version: v1alpha1
18+
- api:
19+
crdVersion: v1
20+
namespaced: true
21+
controller: true
22+
domain: byoh.miscord.win
23+
kind: BothInstallerConfig
24+
path: github.com/miscord-dev/cluster-api-byoh-both/api/v1alpha1
25+
version: v1alpha1
1826
version: "3"
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
24+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
25+
26+
// BothInstallerConfigSpec defines the desired state of BothInstallerConfig
27+
type BothInstallerConfigSpec struct {
28+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
29+
// Important: Run "make" to regenerate code after modifying this file
30+
31+
// Foo is an example field of BothInstallerConfig. Edit bothinstallerconfig_types.go to remove/update
32+
Foo string `json:"foo,omitempty"`
33+
}
34+
35+
// BothInstallerConfigStatus defines the observed state of BothInstallerConfig
36+
type BothInstallerConfigStatus struct {
37+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
38+
// Important: Run "make" to regenerate code after modifying this file
39+
}
40+
41+
//+kubebuilder:object:root=true
42+
//+kubebuilder:subresource:status
43+
44+
// BothInstallerConfig is the Schema for the bothinstallerconfigs API
45+
type BothInstallerConfig struct {
46+
metav1.TypeMeta `json:",inline"`
47+
metav1.ObjectMeta `json:"metadata,omitempty"`
48+
49+
Spec BothInstallerConfigSpec `json:"spec,omitempty"`
50+
Status BothInstallerConfigStatus `json:"status,omitempty"`
51+
}
52+
53+
//+kubebuilder:object:root=true
54+
55+
// BothInstallerConfigList contains a list of BothInstallerConfig
56+
type BothInstallerConfigList struct {
57+
metav1.TypeMeta `json:",inline"`
58+
metav1.ListMeta `json:"metadata,omitempty"`
59+
Items []BothInstallerConfig `json:"items"`
60+
}
61+
62+
func init() {
63+
SchemeBuilder.Register(&BothInstallerConfig{}, &BothInstallerConfigList{})
64+
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 89 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/kustomization.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33
# It should be run by config/default
44
resources:
55
- bases/byoh.miscord.win_bothinstallerconfigtemplates.yaml
6+
- bases/byoh.miscord.win_bothinstallerconfigs.yaml
67
#+kubebuilder:scaffold:crdkustomizeresource
78

89
patchesStrategicMerge:
910
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
1011
# patches here are for enabling the conversion webhook for each CRD
1112
#- patches/webhook_in_bothinstallerconfigtemplates.yaml
13+
#- patches/webhook_in_bothinstallerconfigs.yaml
1214
#+kubebuilder:scaffold:crdkustomizewebhookpatch
1315

1416
# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
1517
# patches here are for enabling the CA injection for each CRD
1618
#- patches/cainjection_in_bothinstallerconfigtemplates.yaml
19+
#- patches/cainjection_in_bothinstallerconfigs.yaml
1720
#+kubebuilder:scaffold:crdkustomizecainjectionpatch
1821

1922
# the following config is for teaching kustomize how to do kustomization for CRDs.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# The following patch adds a directive for certmanager to inject CA into the CRD
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
7+
name: bothinstallerconfigs.byoh.miscord.win
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# The following patch enables a conversion webhook for the CRD
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
name: bothinstallerconfigs.byoh.miscord.win
6+
spec:
7+
conversion:
8+
strategy: Webhook
9+
webhook:
10+
clientConfig:
11+
service:
12+
namespace: system
13+
name: webhook-service
14+
path: /convert
15+
conversionReviewVersions:
16+
- v1
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# permissions for end users to edit bothinstallerconfigs.
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
labels:
6+
app.kubernetes.io/name: clusterrole
7+
app.kubernetes.io/instance: bothinstallerconfig-editor-role
8+
app.kubernetes.io/component: rbac
9+
app.kubernetes.io/created-by: cluster-api-byoh-both
10+
app.kubernetes.io/part-of: cluster-api-byoh-both
11+
app.kubernetes.io/managed-by: kustomize
12+
name: bothinstallerconfig-editor-role
13+
rules:
14+
- apiGroups:
15+
- byoh.miscord.win
16+
resources:
17+
- bothinstallerconfigs
18+
verbs:
19+
- create
20+
- delete
21+
- get
22+
- list
23+
- patch
24+
- update
25+
- watch
26+
- apiGroups:
27+
- byoh.miscord.win
28+
resources:
29+
- bothinstallerconfigs/status
30+
verbs:
31+
- get
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# permissions for end users to view bothinstallerconfigs.
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
labels:
6+
app.kubernetes.io/name: clusterrole
7+
app.kubernetes.io/instance: bothinstallerconfig-viewer-role
8+
app.kubernetes.io/component: rbac
9+
app.kubernetes.io/created-by: cluster-api-byoh-both
10+
app.kubernetes.io/part-of: cluster-api-byoh-both
11+
app.kubernetes.io/managed-by: kustomize
12+
name: bothinstallerconfig-viewer-role
13+
rules:
14+
- apiGroups:
15+
- byoh.miscord.win
16+
resources:
17+
- bothinstallerconfigs
18+
verbs:
19+
- get
20+
- list
21+
- watch
22+
- apiGroups:
23+
- byoh.miscord.win
24+
resources:
25+
- bothinstallerconfigs/status
26+
verbs:
27+
- get
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: byoh.miscord.win/v1alpha1
2+
kind: BothInstallerConfig
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: bothinstallerconfig
6+
app.kubernetes.io/instance: bothinstallerconfig-sample
7+
app.kubernetes.io/part-of: cluster-api-byoh-both
8+
app.kubernetes.io/managed-by: kustomize
9+
app.kubernetes.io/created-by: cluster-api-byoh-both
10+
name: bothinstallerconfig-sample
11+
spec:
12+
# TODO(user): Add fields here
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package controllers
18+
19+
import (
20+
"context"
21+
22+
"k8s.io/apimachinery/pkg/runtime"
23+
ctrl "sigs.k8s.io/controller-runtime"
24+
"sigs.k8s.io/controller-runtime/pkg/client"
25+
"sigs.k8s.io/controller-runtime/pkg/log"
26+
27+
byohmiscordwinv1alpha1 "github.com/miscord-dev/cluster-api-byoh-both/api/v1alpha1"
28+
)
29+
30+
// BothInstallerConfigReconciler reconciles a BothInstallerConfig object
31+
type BothInstallerConfigReconciler struct {
32+
client.Client
33+
Scheme *runtime.Scheme
34+
}
35+
36+
//+kubebuilder:rbac:groups=byoh.miscord.win,resources=bothinstallerconfigs,verbs=get;list;watch;create;update;patch;delete
37+
//+kubebuilder:rbac:groups=byoh.miscord.win,resources=bothinstallerconfigs/status,verbs=get;update;patch
38+
//+kubebuilder:rbac:groups=byoh.miscord.win,resources=bothinstallerconfigs/finalizers,verbs=update
39+
40+
// Reconcile is part of the main kubernetes reconciliation loop which aims to
41+
// move the current state of the cluster closer to the desired state.
42+
// TODO(user): Modify the Reconcile function to compare the state specified by
43+
// the BothInstallerConfig object against the actual cluster state, and then
44+
// perform operations to make the cluster state reflect the state specified by
45+
// the user.
46+
//
47+
// For more details, check Reconcile and its Result here:
48+
// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.14.1/pkg/reconcile
49+
func (r *BothInstallerConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
50+
_ = log.FromContext(ctx)
51+
52+
// TODO(user): your logic here
53+
54+
return ctrl.Result{}, nil
55+
}
56+
57+
// SetupWithManager sets up the controller with the Manager.
58+
func (r *BothInstallerConfigReconciler) SetupWithManager(mgr ctrl.Manager) error {
59+
return ctrl.NewControllerManagedBy(mgr).
60+
For(&byohmiscordwinv1alpha1.BothInstallerConfig{}).
61+
Complete(r)
62+
}

0 commit comments

Comments
 (0)