Skip to content

Commit dd2a8cd

Browse files
author
Nitish Tiwari
authored
Add ClusterAddon and ClusterReconciler controllers and types (#39)
Part of #29
1 parent 00ff9b3 commit dd2a8cd

14 files changed

+636
-4
lines changed

PROJECT

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,18 @@ resources:
5353
kind: HetznerNodeImageRelease
5454
path: github.com/syself/cluster-stack-operator/api/v1alpha1
5555
version: v1alpha1
56+
- api:
57+
crdVersion: v1
58+
namespaced: true
59+
controller: true
60+
domain: syself.io
61+
group: infrastructure.cluster.x-k8s.io
62+
kind: ClusterAddon
63+
path: github.com/syself/cluster-stack-operator/api/v1alpha1
64+
version: v1alpha1
65+
- controller: true
66+
domain: syself.io
67+
group: infrastructure.cluster.x-k8s.io
68+
kind: ClusterReconciler
69+
version: v1alpha1
5670
version: "3"

api/v1alpha1/clusteraddon_types.go

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+
corev1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
25+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
26+
27+
// ClusterAddonSpec defines the desired state of ClusterAddon
28+
type ClusterAddonSpec struct {
29+
ClusterStack string `json:"clusterStack,omitempty"`
30+
ClusterAddonVersion string `json:"clusterAddonVersion,omitempty"`
31+
ClusterRef *corev1.ObjectReference `json:"clusterRef,omitempty"`
32+
}
33+
34+
// ClusterAddonStatus defines the observed state of ClusterAddon
35+
type ClusterAddonStatus 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+
//+kubebuilder:subresource:status
42+
43+
// ClusterAddon is the Schema for the clusteraddons API
44+
type ClusterAddon struct {
45+
metav1.TypeMeta `json:",inline"`
46+
metav1.ObjectMeta `json:"metadata,omitempty"`
47+
48+
OwnerReferences metav1.OwnerReference `json:"ownerReferences"`
49+
Spec ClusterAddonSpec `json:"spec,omitempty"`
50+
Status ClusterAddonStatus `json:"status,omitempty"`
51+
}
52+
53+
//+kubebuilder:object:root=true
54+
55+
// ClusterAddonList contains a list of ClusterAddon
56+
type ClusterAddonList struct {
57+
metav1.TypeMeta `json:",inline"`
58+
metav1.ListMeta `json:"metadata,omitempty"`
59+
Items []ClusterAddon `json:"items"`
60+
}
61+
62+
func init() {
63+
SchemeBuilder.Register(&ClusterAddon{}, &ClusterAddonList{})
64+
}

api/v1alpha1/zz_generated.deepcopy.go

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

cmd/main.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ import (
2525
_ "k8s.io/client-go/plugin/pkg/client/auth"
2626

2727
caph "github.com/syself/cluster-api-provider-hetzner/api/v1beta1"
28-
csov1alpha1 "github.com/syself/cluster-stack-operator/api/v1alpha1"
29-
"github.com/syself/cluster-stack-operator/internal/controller"
3028
"k8s.io/apimachinery/pkg/runtime"
3129
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3230
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
3331
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
3432
ctrl "sigs.k8s.io/controller-runtime"
3533
"sigs.k8s.io/controller-runtime/pkg/healthz"
3634
"sigs.k8s.io/controller-runtime/pkg/log/zap"
35+
36+
csov1alpha1 "github.com/syself/cluster-stack-operator/api/v1alpha1"
37+
"github.com/syself/cluster-stack-operator/internal/controller"
3738
//+kubebuilder:scaffold:imports
3839
)
3940

@@ -48,7 +49,6 @@ func init() {
4849

4950
utilruntime.Must(csov1alpha1.AddToScheme(scheme))
5051
utilruntime.Must(caph.AddToScheme(scheme))
51-
5252
//+kubebuilder:scaffold:scheme
5353
}
5454

@@ -129,6 +129,20 @@ func main() {
129129
setupLog.Error(err, "unable to create controller", "controller", "HetznerNodeImageRelease")
130130
os.Exit(1)
131131
}
132+
if err = (&controller.ClusterAddonReconciler{
133+
Client: mgr.GetClient(),
134+
Scheme: mgr.GetScheme(),
135+
}).SetupWithManager(mgr); err != nil {
136+
setupLog.Error(err, "unable to create controller", "controller", "ClusterAddon")
137+
os.Exit(1)
138+
}
139+
if err = (&controller.ClusterReconcilerReconciler{
140+
Client: mgr.GetClient(),
141+
Scheme: mgr.GetScheme(),
142+
}).SetupWithManager(mgr); err != nil {
143+
setupLog.Error(err, "unable to create controller", "controller", "ClusterReconciler")
144+
os.Exit(1)
145+
}
132146
//+kubebuilder:scaffold:builder
133147

134148
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.12.0
7+
name: clusteraddons.infrastructure.cluster.x-k8s.io.syself.io
8+
spec:
9+
group: infrastructure.cluster.x-k8s.io.syself.io
10+
names:
11+
kind: ClusterAddon
12+
listKind: ClusterAddonList
13+
plural: clusteraddons
14+
singular: clusteraddon
15+
scope: Namespaced
16+
versions:
17+
- name: v1alpha1
18+
schema:
19+
openAPIV3Schema:
20+
description: ClusterAddon is the Schema for the clusteraddons API
21+
properties:
22+
apiVersion:
23+
description: 'APIVersion defines the versioned schema of this representation
24+
of an object. Servers should convert recognized schemas to the latest
25+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
26+
type: string
27+
kind:
28+
description: 'Kind is a string value representing the REST resource this
29+
object represents. Servers may infer this from the endpoint the client
30+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
31+
type: string
32+
metadata:
33+
type: object
34+
ownerReferences:
35+
description: OwnerReference contains enough information to let you identify
36+
an owning object. An owning object must be in the same namespace as
37+
the dependent, or be cluster-scoped, so there is no namespace field.
38+
properties:
39+
apiVersion:
40+
description: API version of the referent.
41+
type: string
42+
blockOwnerDeletion:
43+
description: If true, AND if the owner has the "foregroundDeletion"
44+
finalizer, then the owner cannot be deleted from the key-value store
45+
until this reference is removed. See https://kubernetes.io/docs/concepts/architecture/garbage-collection/#foreground-deletion
46+
for how the garbage collector interacts with this field and enforces
47+
the foreground deletion. Defaults to false. To set this field, a
48+
user needs "delete" permission of the owner, otherwise 422 (Unprocessable
49+
Entity) will be returned.
50+
type: boolean
51+
controller:
52+
description: If true, this reference points to the managing controller.
53+
type: boolean
54+
kind:
55+
description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
56+
type: string
57+
name:
58+
description: 'Name of the referent. More info: http://kubernetes.io/docs/user-guide/identifiers#names'
59+
type: string
60+
uid:
61+
description: 'UID of the referent. More info: http://kubernetes.io/docs/user-guide/identifiers#uids'
62+
type: string
63+
required:
64+
- apiVersion
65+
- kind
66+
- name
67+
- uid
68+
type: object
69+
x-kubernetes-map-type: atomic
70+
spec:
71+
description: ClusterAddonSpec defines the desired state of ClusterAddon
72+
properties:
73+
clusterAddonVersion:
74+
type: string
75+
clusterRef:
76+
description: "ObjectReference contains enough information to let you
77+
inspect or modify the referred object. --- New uses of this type
78+
are discouraged because of difficulty describing its usage when
79+
embedded in APIs. 1. Ignored fields. It includes many fields which
80+
are not generally honored. For instance, ResourceVersion and FieldPath
81+
are both very rarely valid in actual usage. 2. Invalid usage help.
82+
\ It is impossible to add specific help for individual usage. In
83+
most embedded usages, there are particular restrictions like, \"must
84+
refer only to types A and B\" or \"UID not honored\" or \"name must
85+
be restricted\". Those cannot be well described when embedded. 3.
86+
Inconsistent validation. Because the usages are different, the
87+
validation rules are different by usage, which makes it hard for
88+
users to predict what will happen. 4. The fields are both imprecise
89+
and overly precise. Kind is not a precise mapping to a URL. This
90+
can produce ambiguity during interpretation and require a REST mapping.
91+
\ In most cases, the dependency is on the group,resource tuple and
92+
the version of the actual struct is irrelevant. 5. We cannot easily
93+
change it. Because this type is embedded in many locations, updates
94+
to this type will affect numerous schemas. Don't make new APIs
95+
embed an underspecified API type they do not control. \n Instead
96+
of using this type, create a locally provided and used type that
97+
is well-focused on your reference. For example, ServiceReferences
98+
for admission registration: https://github.com/kubernetes/api/blob/release-1.17/admissionregistration/v1/types.go#L533
99+
."
100+
properties:
101+
apiVersion:
102+
description: API version of the referent.
103+
type: string
104+
fieldPath:
105+
description: 'If referring to a piece of an object instead of
106+
an entire object, this string should contain a valid JSON/Go
107+
field access statement, such as desiredState.manifest.containers[2].
108+
For example, if the object reference is to a container within
109+
a pod, this would take on a value like: "spec.containers{name}"
110+
(where "name" refers to the name of the container that triggered
111+
the event) or if no container name is specified "spec.containers[2]"
112+
(container with index 2 in this pod). This syntax is chosen
113+
only to have some well-defined way of referencing a part of
114+
an object. TODO: this design is not final and this field is
115+
subject to change in the future.'
116+
type: string
117+
kind:
118+
description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
119+
type: string
120+
name:
121+
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
122+
type: string
123+
namespace:
124+
description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
125+
type: string
126+
resourceVersion:
127+
description: 'Specific resourceVersion to which this reference
128+
is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency'
129+
type: string
130+
uid:
131+
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
132+
type: string
133+
type: object
134+
x-kubernetes-map-type: atomic
135+
clusterStack:
136+
type: string
137+
type: object
138+
status:
139+
description: ClusterAddonStatus defines the observed state of ClusterAddon
140+
type: object
141+
required:
142+
- ownerReferences
143+
type: object
144+
served: true
145+
storage: true
146+
subresources:
147+
status: {}

0 commit comments

Comments
 (0)