Skip to content

Commit 756f1a2

Browse files
authored
Basic EtcdCluster custom resource (#9) (#15)
Generated and wrote the most basic EtcdCluster custom resource. See #9
1 parent d18bf37 commit 756f1a2

18 files changed

+784
-12
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Dockerfile.cross
1616
*.out
1717

1818
# Kubernetes Generated files - skip generated files, except for vendored files
19-
19+
vendor
2020
!vendor/**/zz_generated.*
2121

2222
# editor and IDE paraphernalia

PROJECT

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,14 @@ layout:
77
- go.kubebuilder.io/v4
88
projectName: etcd-operator
99
repo: github.com/aenix-io/etcd-operator
10+
resources:
11+
- api:
12+
crdVersion: v1
13+
namespaced: true
14+
controller: true
15+
domain: etcd.aenix.io
16+
group: etcd.aenix.io
17+
kind: EtcdCluster
18+
path: github.com/aenix-io/etcd-operator/api/v1alpha1
19+
version: v1alpha1
1020
version: "3"

api/v1alpha1/etcdcluster_types.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
Copyright 2024.
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+
"k8s.io/apimachinery/pkg/api/resource"
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+
type Storage struct {
28+
StorageClass string `json:"storageClass"`
29+
Size resource.Quantity `json:"size"`
30+
}
31+
32+
// EtcdClusterSpec defines the desired state of EtcdCluster
33+
type EtcdClusterSpec struct {
34+
// Replicas is the count of etcd instances in cluster.
35+
// +optional
36+
// +kubebuilder:default:=3
37+
Replicas uint `json:"replicas,omitempty"`
38+
Storage Storage `json:"storage,omitempty"`
39+
}
40+
41+
// EtcdClusterStatus defines the observed state of EtcdCluster
42+
type EtcdClusterStatus struct {
43+
Conditions []metav1.Condition `json:"conditions,omitempty"`
44+
}
45+
46+
//+kubebuilder:object:root=true
47+
//+kubebuilder:subresource:status
48+
49+
// EtcdCluster is the Schema for the etcdclusters API
50+
type EtcdCluster struct {
51+
metav1.TypeMeta `json:",inline"`
52+
metav1.ObjectMeta `json:"metadata,omitempty"`
53+
54+
Spec EtcdClusterSpec `json:"spec,omitempty"`
55+
Status EtcdClusterStatus `json:"status,omitempty"`
56+
}
57+
58+
//+kubebuilder:object:root=true
59+
60+
// EtcdClusterList contains a list of EtcdCluster
61+
type EtcdClusterList struct {
62+
metav1.TypeMeta `json:",inline"`
63+
metav1.ListMeta `json:"metadata,omitempty"`
64+
Items []EtcdCluster `json:"items"`
65+
}
66+
67+
func init() {
68+
SchemeBuilder.Register(&EtcdCluster{}, &EtcdClusterList{})
69+
}

api/v1alpha1/groupversion_info.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2024.
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 contains API Schema definitions for the etcd.aenix.io v1alpha1 API group
18+
// +kubebuilder:object:generate=true
19+
// +groupName=etcd.aenix.io.etcd.aenix.io
20+
package v1alpha1
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "etcd.aenix.io.etcd.aenix.io", Version: "v1alpha1"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 139 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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ import (
3333
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3434
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3535
"sigs.k8s.io/controller-runtime/pkg/webhook"
36+
37+
etcdaenixiov1alpha1 "github.com/aenix-io/etcd-operator/api/v1alpha1"
38+
"github.com/aenix-io/etcd-operator/internal/controller"
3639
//+kubebuilder:scaffold:imports
3740
)
3841

@@ -44,6 +47,7 @@ var (
4447
func init() {
4548
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
4649

50+
utilruntime.Must(etcdaenixiov1alpha1.AddToScheme(scheme))
4751
//+kubebuilder:scaffold:scheme
4852
}
4953

@@ -118,6 +122,13 @@ func main() {
118122
os.Exit(1)
119123
}
120124

125+
if err = (&controller.EtcdClusterReconciler{
126+
Client: mgr.GetClient(),
127+
Scheme: mgr.GetScheme(),
128+
}).SetupWithManager(mgr); err != nil {
129+
setupLog.Error(err, "unable to create controller", "controller", "EtcdCluster")
130+
os.Exit(1)
131+
}
121132
//+kubebuilder:scaffold:builder
122133

123134
if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {

0 commit comments

Comments
 (0)