Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.

Commit ce2e83d

Browse files
adding NestedControlPlane & NestedCluster controllers
Signed-off-by: Chris Hein <[email protected]>
1 parent 163817c commit ce2e83d

36 files changed

+1804
-234
lines changed

PROJECT

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
domain: cluster.x-k8s.io
2-
layout: go.kubebuilder.io/v3
2+
layout:
3+
- go.kubebuilder.io/v3
34
multigroup: true
45
projectName: cluster-api-provider-nested
56
repo: sigs.k8s.io/cluster-api-provider-nested
@@ -22,4 +23,13 @@ resources:
2223
group: controlplane
2324
kind: NestedControllerManager
2425
version: v1alpha4
25-
version: 3-alpha
26+
- api:
27+
crdVersion: v1
28+
namespaced: true
29+
controller: true
30+
domain: cluster.x-k8s.io
31+
group: infrastructure
32+
kind: NestedCluster
33+
path: sigs.k8s.io/cluster-api-provider-nested/apis/infrastructure/v1alpha4
34+
version: v1alpha4
35+
version: "3"

apis/controlplane/v1alpha4/nestedapiserver_types.go

+24-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ type NestedAPIServerStatus struct {
4141
}
4242

4343
//+kubebuilder:object:root=true
44-
//+kubebuilder:resource:scope=Namespaced,path=nestedapiservers,shortName=nkas
45-
//+kubebuilder:categories=capi,capn
44+
//+kubebuilder:resource:scope=Namespaced,shortName=nkas,categories=capi;capn
4645
//+kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
4746
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
4847
//+kubebuilder:subresource:status
@@ -68,3 +67,26 @@ type NestedAPIServerList struct {
6867
func init() {
6968
SchemeBuilder.Register(&NestedAPIServer{}, &NestedAPIServerList{})
7069
}
70+
71+
var _ addonv1alpha1.CommonObject = &NestedAPIServer{}
72+
var _ addonv1alpha1.Patchable = &NestedAPIServer{}
73+
74+
func (c *NestedAPIServer) ComponentName() string {
75+
return string(APIServer)
76+
}
77+
78+
func (c *NestedAPIServer) CommonSpec() addonv1alpha1.CommonSpec {
79+
return c.Spec.CommonSpec
80+
}
81+
82+
func (c *NestedAPIServer) GetCommonStatus() addonv1alpha1.CommonStatus {
83+
return c.Status.CommonStatus
84+
}
85+
86+
func (c *NestedAPIServer) SetCommonStatus(s addonv1alpha1.CommonStatus) {
87+
c.Status.CommonStatus = s
88+
}
89+
90+
func (c *NestedAPIServer) PatchSpec() addonv1alpha1.PatchSpec {
91+
return c.Spec.PatchSpec
92+
}

apis/controlplane/v1alpha4/nestedcontrollermanager_types.go

+24-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ type NestedControllerManagerStatus struct {
3636
}
3737

3838
//+kubebuilder:object:root=true
39-
//+kubebuilder:resource:scope=Namespaced,path=nestedcontrollermanager,shortName=nkcm
40-
//+kubebuilder:categories=capi,capn
39+
//+kubebuilder:resource:scope=Namespaced,shortName=nkcm,categories=capi;capn
4140
//+kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
4241
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
4342
//+kubebuilder:subresource:status
@@ -63,3 +62,26 @@ type NestedControllerManagerList struct {
6362
func init() {
6463
SchemeBuilder.Register(&NestedControllerManager{}, &NestedControllerManagerList{})
6564
}
65+
66+
var _ addonv1alpha1.CommonObject = &NestedControllerManager{}
67+
var _ addonv1alpha1.Patchable = &NestedControllerManager{}
68+
69+
func (c *NestedControllerManager) ComponentName() string {
70+
return string(ControllerManager)
71+
}
72+
73+
func (c *NestedControllerManager) CommonSpec() addonv1alpha1.CommonSpec {
74+
return c.Spec.CommonSpec
75+
}
76+
77+
func (c *NestedControllerManager) GetCommonStatus() addonv1alpha1.CommonStatus {
78+
return c.Status.CommonStatus
79+
}
80+
81+
func (c *NestedControllerManager) SetCommonStatus(s addonv1alpha1.CommonStatus) {
82+
c.Status.CommonStatus = s
83+
}
84+
85+
func (c *NestedControllerManager) PatchSpec() addonv1alpha1.PatchSpec {
86+
return c.Spec.PatchSpec
87+
}

apis/controlplane/v1alpha4/nestedcontrolplane_types.go

+15-8
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,21 @@ limitations under the License.
1717
package v1alpha4
1818

1919
import (
20+
"context"
21+
2022
corev1 "k8s.io/api/core/v1"
2123
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2224
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
25+
"sigs.k8s.io/cluster-api/util"
26+
"sigs.k8s.io/controller-runtime/pkg/client"
27+
)
28+
29+
const (
30+
NestedControlPlaneFinalizer = "nested.controlplane.cluster.x-k8s.io"
2331
)
2432

2533
// NestedControlPlaneSpec defines the desired state of NestedControlPlane
2634
type NestedControlPlaneSpec struct {
27-
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
28-
// +optional
29-
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
30-
3135
// EtcdRef is the reference to the NestedEtcd
3236
EtcdRef *corev1.ObjectReference `json:"etcd,omitempty"`
3337

@@ -87,10 +91,9 @@ type NestedControlPlaneStatusAPIServer struct {
8791
ServiceCIDR string `json:"serviceCidr,omitempty"`
8892
}
8993

90-
// +kubebuilder:object:root=true
91-
//+kubebuilder:resource:scope=Namespaced,shortName=ncp
92-
//+kubebuilder:categories=capi,capn
93-
//+kubebuilder:printcolumn:name="Ready",type="boolean",JSONPath=".status.rady"
94+
//+kubebuilder:object:root=true
95+
//+kubebuilder:resource:scope=Namespaced,shortName=ncp,categories=capi;capn
96+
//+kubebuilder:printcolumn:name="Ready",type="boolean",JSONPath=".status.ready"
9497
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
9598
//+kubebuilder:subresource:status
9699

@@ -115,3 +118,7 @@ type NestedControlPlaneList struct {
115118
func init() {
116119
SchemeBuilder.Register(&NestedControlPlane{}, &NestedControlPlaneList{})
117120
}
121+
122+
func (r *NestedControlPlane) GetOwnerCluster(ctx context.Context, cli client.Client) (cluster *clusterv1.Cluster, err error) {
123+
return util.GetOwnerCluster(ctx, cli, r.ObjectMeta)
124+
}

apis/controlplane/v1alpha4/nestedetcd_types.go

+24-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ type NestedEtcdAddress struct {
5353
}
5454

5555
//+kubebuilder:object:root=true
56-
//+kubebuilder:resource:scope=Namespaced,path=nestedetcds,shortName=netcd
57-
//+kubebuilder:categories=capi,capn
56+
//+kubebuilder:resource:scope=Namespaced,shortName=netcd,categories=capi;capn
5857
//+kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase"
5958
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
6059
//+kubebuilder:subresource:status
@@ -80,3 +79,26 @@ type NestedEtcdList struct {
8079
func init() {
8180
SchemeBuilder.Register(&NestedEtcd{}, &NestedEtcdList{})
8281
}
82+
83+
var _ addonv1alpha1.CommonObject = &NestedEtcd{}
84+
var _ addonv1alpha1.Patchable = &NestedEtcd{}
85+
86+
func (c *NestedEtcd) ComponentName() string {
87+
return string(Etcd)
88+
}
89+
90+
func (c *NestedEtcd) CommonSpec() addonv1alpha1.CommonSpec {
91+
return c.Spec.CommonSpec
92+
}
93+
94+
func (c *NestedEtcd) GetCommonStatus() addonv1alpha1.CommonStatus {
95+
return c.Status.CommonStatus
96+
}
97+
98+
func (c *NestedEtcd) SetCommonStatus(s addonv1alpha1.CommonStatus) {
99+
c.Status.CommonStatus = s
100+
}
101+
102+
func (c *NestedEtcd) PatchSpec() addonv1alpha1.PatchSpec {
103+
return c.Spec.PatchSpec
104+
}

apis/controlplane/v1alpha4/zz_generated.deepcopy.go

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
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 v1alpha4 contains API Schema definitions for the infrastructure v1alpha4 API group
18+
//+kubebuilder:object:generate=true
19+
//+groupName=infrastructure.cluster.x-k8s.io
20+
package v1alpha4
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: "infrastructure.cluster.x-k8s.io", Version: "v1alpha4"}
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+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
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 v1alpha4
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha4"
22+
)
23+
24+
// NestedClusterSpec defines the desired state of NestedCluster
25+
type NestedClusterSpec struct {
26+
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
27+
// +optional
28+
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
29+
}
30+
31+
// NestedClusterStatus defines the observed state of NestedCluster
32+
type NestedClusterStatus struct {
33+
// Ready is when the NestedControlPlane has a API server URL.
34+
// +optional
35+
Ready bool `json:"ready,omitempty"`
36+
}
37+
38+
//+kubebuilder:object:root=true
39+
//+kubebuilder:resource:scope=Namespaced,shortName=nc,categories=capi;capn
40+
//+kubebuilder:printcolumn:name="Ready",type="boolean",JSONPath=".status.ready"
41+
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
42+
//+kubebuilder:subresource:status
43+
44+
// NestedCluster is the Schema for the nestedclusters API
45+
type NestedCluster struct {
46+
metav1.TypeMeta `json:",inline"`
47+
metav1.ObjectMeta `json:"metadata,omitempty"`
48+
49+
Spec NestedClusterSpec `json:"spec,omitempty"`
50+
Status NestedClusterStatus `json:"status,omitempty"`
51+
}
52+
53+
//+kubebuilder:object:root=true
54+
55+
// NestedClusterList contains a list of NestedCluster
56+
type NestedClusterList struct {
57+
metav1.TypeMeta `json:",inline"`
58+
metav1.ListMeta `json:"metadata,omitempty"`
59+
Items []NestedCluster `json:"items"`
60+
}
61+
62+
func init() {
63+
SchemeBuilder.Register(&NestedCluster{}, &NestedClusterList{})
64+
}

0 commit comments

Comments
 (0)