Skip to content

Commit 402d82d

Browse files
committed
kubebuilder create api --group core --version v1alpha1 --kind DNSRecord
1 parent bf70a85 commit 402d82d

File tree

11 files changed

+288
-0
lines changed

11 files changed

+288
-0
lines changed

controller/PROJECT

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

controller/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.

controller/config/crd/kustomization.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ resources:
2121
- bases/core.kalm.dev_tenants.yaml
2222
- bases/core.kalm.dev_clusterresourcequotas.yaml
2323
- bases/core.kalm.dev_domains.yaml
24+
- bases/core.kalm.dev_dnsrecords.yaml
2425
# +kubebuilder:scaffold:crdkustomizeresource
2526

2627
patchesStrategicMerge:
@@ -42,6 +43,7 @@ patchesStrategicMerge:
4243
#- patches/webhook_in_acmeservers.yaml
4344
#- patches/webhook_in_clusterresourcequota.yaml
4445
#- patches/webhook_in_domains.yaml
46+
#- patches/webhook_in_dnsrecords.yaml
4547
# +kubebuilder:scaffold:crdkustomizewebhookpatch
4648

4749
# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
@@ -62,6 +64,7 @@ patchesStrategicMerge:
6264
#- patches/cainjection_in_acmeservers.yaml
6365
#- patches/cainjection_in_clusterresourcequota.yaml
6466
#- patches/cainjection_in_domains.yaml
67+
#- patches/cainjection_in_dnsrecords.yaml
6568
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
6669

6770
# the following config is for teaching kustomize how to do kustomization for CRDs.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# The following patch adds a directive for certmanager to inject CA into the CRD
2+
# CRD conversion requires k8s 1.13 or later.
3+
apiVersion: apiextensions.k8s.io/v1beta1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
annotations:
7+
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
8+
name: dnsrecords.core.kalm.dev
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# The following patch enables conversion webhook for CRD
2+
# CRD conversion requires k8s 1.13 or later.
3+
apiVersion: apiextensions.k8s.io/v1beta1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
name: dnsrecords.core.kalm.dev
7+
spec:
8+
conversion:
9+
strategy: Webhook
10+
webhookClientConfig:
11+
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
12+
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
13+
caBundle: Cg==
14+
service:
15+
namespace: system
16+
name: webhook-service
17+
path: /convert
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# permissions for end users to edit dnsrecords.
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
name: dnsrecord-editor-role
6+
rules:
7+
- apiGroups:
8+
- core.kalm.dev
9+
resources:
10+
- dnsrecords
11+
verbs:
12+
- create
13+
- delete
14+
- get
15+
- list
16+
- patch
17+
- update
18+
- watch
19+
- apiGroups:
20+
- core.kalm.dev
21+
resources:
22+
- dnsrecords/status
23+
verbs:
24+
- get
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# permissions for end users to view dnsrecords.
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
name: dnsrecord-viewer-role
6+
rules:
7+
- apiGroups:
8+
- core.kalm.dev
9+
resources:
10+
- dnsrecords
11+
verbs:
12+
- get
13+
- list
14+
- watch
15+
- apiGroups:
16+
- core.kalm.dev
17+
resources:
18+
- dnsrecords/status
19+
verbs:
20+
- get
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: core.kalm.dev/v1alpha1
2+
kind: DNSRecord
3+
metadata:
4+
name: dnsrecord-sample
5+
spec:
6+
# Add fields here
7+
foo: bar
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.
14+
*/
15+
16+
package controllers
17+
18+
import (
19+
"context"
20+
21+
"github.com/go-logr/logr"
22+
"k8s.io/apimachinery/pkg/runtime"
23+
ctrl "sigs.k8s.io/controller-runtime"
24+
"sigs.k8s.io/controller-runtime/pkg/client"
25+
26+
corev1alpha1 "github.com/kalmhq/kalm/controller/api/v1alpha1"
27+
)
28+
29+
// DNSRecordReconciler reconciles a DNSRecord object
30+
type DNSRecordReconciler struct {
31+
client.Client
32+
Log logr.Logger
33+
Scheme *runtime.Scheme
34+
}
35+
36+
// +kubebuilder:rbac:groups=core.kalm.dev,resources=dnsrecords,verbs=get;list;watch;create;update;patch;delete
37+
// +kubebuilder:rbac:groups=core.kalm.dev,resources=dnsrecords/status,verbs=get;update;patch
38+
39+
func (r *DNSRecordReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
40+
_ = context.Background()
41+
_ = r.Log.WithValues("dnsrecord", req.NamespacedName)
42+
43+
// your logic here
44+
45+
return ctrl.Result{}, nil
46+
}
47+
48+
func (r *DNSRecordReconciler) SetupWithManager(mgr ctrl.Manager) error {
49+
return ctrl.NewControllerManagedBy(mgr).
50+
For(&corev1alpha1.DNSRecord{}).
51+
Complete(r)
52+
}

0 commit comments

Comments
 (0)