Skip to content

Commit ab2c625

Browse files
authored
v1alpha4 support (#326)
* v1alpha4 support * Fix rbac rules
1 parent c9fc9b0 commit ab2c625

20 files changed

+1331
-278
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ ifeq (, $(shell which controller-gen))
7878
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
7979
cd $$CONTROLLER_GEN_TMP_DIR ;\
8080
go mod init tmp ;\
81-
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.6 ;\
81+
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.1 ;\
8282
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
8383
}
8484
CONTROLLER_GEN=$(GOBIN)/controller-gen

api/v1alpha4/groupversion_info.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
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+
)

api/v1alpha4/ibmvpccluster_types.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
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+
// 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+
const (
28+
// ClusterFinalizer allows DockerClusterReconciler to clean up resources associated with DockerCluster before
29+
// removing it from the apiserver.
30+
ClusterFinalizer = "ibmvpccluster.infrastructure.cluster.x-k8s.io"
31+
)
32+
33+
// IBMVPCClusterSpec defines the desired state of IBMVPCCluster
34+
type IBMVPCClusterSpec struct {
35+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
36+
// Important: Run "make" to regenerate code after modifying this file
37+
38+
// The IBM Cloud Region the cluster lives in.
39+
Region string `json:"region"`
40+
41+
// The VPC resources should be created under the resource group
42+
ResourceGroup string `json:"resourceGroup"`
43+
44+
// The Name of VPC
45+
VPC string `json:"vpc,omitempty"`
46+
47+
// The Name of availability zone
48+
Zone string `json:"zone,omitempty"`
49+
50+
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
51+
// +optional
52+
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
53+
}
54+
55+
// IBMVPCClusterStatus defines the observed state of IBMVPCCluster
56+
type IBMVPCClusterStatus struct {
57+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
58+
// Important: Run "make" to regenerate code after modifying this file
59+
VPC VPC `json:"vpc,omitempty"`
60+
// Bastion Instance `json:"bastion,omitempty"`
61+
Ready bool `json:"ready"`
62+
Subnet Subnet `json:"subnet,omitempty"`
63+
APIEndpoint APIEndpoint `json:"apiEndpoint,omitempty"`
64+
}
65+
66+
type VPC struct {
67+
ID string `json:"id"`
68+
Name string `json:"name"`
69+
}
70+
71+
// +kubebuilder:object:root=true
72+
// +kubebuilder:resource:path=ibmvpcclusters,scope=Namespaced,categories=cluster-api
73+
// +kubebuilder:storageversion
74+
// +kubebuilder:subresource:status
75+
// +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels.cluster\\.x-k8s\\.io/cluster-name",description="Cluster to which this IBMVPCCluster belongs"
76+
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Cluster infrastructure is ready for IBM VPC instances"
77+
78+
// IBMVPCCluster is the Schema for the ibmvpcclusters API
79+
type IBMVPCCluster struct {
80+
metav1.TypeMeta `json:",inline"`
81+
metav1.ObjectMeta `json:"metadata,omitempty"`
82+
83+
Spec IBMVPCClusterSpec `json:"spec,omitempty"`
84+
Status IBMVPCClusterStatus `json:"status,omitempty"`
85+
}
86+
87+
// +kubebuilder:object:root=true
88+
89+
// IBMVPCClusterList contains a list of IBMVPCCluster
90+
type IBMVPCClusterList struct {
91+
metav1.TypeMeta `json:",inline"`
92+
metav1.ListMeta `json:"metadata,omitempty"`
93+
Items []IBMVPCCluster `json:"items"`
94+
}
95+
96+
func init() {
97+
SchemeBuilder.Register(&IBMVPCCluster{}, &IBMVPCClusterList{})
98+
}

api/v1alpha4/ibmvpcmachine_types.go

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
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+
v1 "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+
const (
27+
// MachineFinalizer allows IBMVPCMachineReconciler to clean up resources associated with IBMVPCMachine before
28+
// removing it from the apiserver.
29+
MachineFinalizer = "ibmvpcmachine.infrastructure.cluster.x-k8s.io"
30+
)
31+
32+
// IBMVPCMachineSpec defines the desired state of IBMVPCMachine
33+
type IBMVPCMachineSpec struct {
34+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
35+
// Important: Run "make" to regenerate code after modifying this file
36+
37+
// Name of the instance
38+
Name string `json:"name,omitempty"`
39+
40+
// Image is the id of OS image which would be install on the instance.
41+
// Example: r134-ed3f775f-ad7e-4e37-ae62-7199b4988b00
42+
// TODO: allow user to specify a image name is much reasonable. Example: ibm-ubuntu-18-04-1-minimal-amd64-2
43+
Image string `json:"image"`
44+
45+
// Zone is the place where the instance should be created. Example: us-south-3
46+
// TODO: Actually zone is transparent to user. The field user can access is location. Example: Dallas 2
47+
Zone string `json:"zone"`
48+
49+
// Profile indicates the flavor of instance. Example: bx2-8x32 means 8 vCPUs 32 GB RAM 16 Gbps
50+
// TODO: add a reference link of profile
51+
Profile string `json:"profile"`
52+
53+
// ProviderID is the unique identifier as specified by the cloud provider.
54+
// +optional
55+
ProviderID *string `json:"providerID,omitempty"`
56+
57+
// PrimaryNetworkInterface is required to specify subnet
58+
PrimaryNetworkInterface NetworkInterface `json:"primaryNetworkInterface,omitempty"`
59+
60+
// SSHKeys is the SSH pub keys that will be used to access VM
61+
SSHKeys []*string `json:"sshKeys,omitempty"`
62+
}
63+
64+
// IBMVPCMachineStatus defines the observed state of IBMVPCMachine
65+
type IBMVPCMachineStatus struct {
66+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
67+
// Important: Run "make" to regenerate code after modifying this file
68+
69+
InstanceID string `json:"instanceID,omitempty"`
70+
71+
Ready bool `json:"ready"`
72+
73+
// Addresses contains the GCP instance associated addresses.
74+
Addresses []v1.NodeAddress `json:"addresses,omitempty"`
75+
76+
// InstanceStatus is the status of the GCP instance for this machine.
77+
// +optional
78+
InstanceStatus string `json:"instanceState,omitempty"`
79+
}
80+
81+
// +kubebuilder:object:root=true
82+
// +kubebuilder:resource:path=ibmvpcmachines,scope=Namespaced,categories=cluster-api
83+
// +kubebuilder:storageversion
84+
// +kubebuilder:subresource:status
85+
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Cluster infrastructure is ready for IBM VPC instances"
86+
87+
// IBMVPCMachine is the Schema for the ibmvpcmachines API
88+
type IBMVPCMachine struct {
89+
metav1.TypeMeta `json:",inline"`
90+
metav1.ObjectMeta `json:"metadata,omitempty"`
91+
92+
Spec IBMVPCMachineSpec `json:"spec,omitempty"`
93+
Status IBMVPCMachineStatus `json:"status,omitempty"`
94+
}
95+
96+
// +kubebuilder:object:root=true
97+
98+
// IBMVPCMachineList contains a list of IBMVPCMachine
99+
type IBMVPCMachineList struct {
100+
metav1.TypeMeta `json:",inline"`
101+
metav1.ListMeta `json:"metadata,omitempty"`
102+
Items []IBMVPCMachine `json:"items"`
103+
}
104+
105+
func init() {
106+
SchemeBuilder.Register(&IBMVPCMachine{}, &IBMVPCMachineList{})
107+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package v1alpha4
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
)
6+
7+
// IBMVPCMachineTemplateSpec defines the desired state of IBMVPCMachineTemplate
8+
type IBMVPCMachineTemplateSpec struct {
9+
Template IBMVPCMachineTemplateResource `json:"template"`
10+
}
11+
12+
// IBMVPCMachineTemplateResource describes the data needed to create am IBMVPCMachine from a template
13+
type IBMVPCMachineTemplateResource struct {
14+
// Spec is the specification of the desired behavior of the machine.
15+
Spec IBMVPCMachineSpec `json:"spec"`
16+
}
17+
18+
// +kubebuilder:object:root=true
19+
// +kubebuilder:resource:path=ibmvpcmachinetemplates,scope=Namespaced,categories=cluster-api
20+
// +kubebuilder:storageversion
21+
22+
// IBMVPCMachineTemplate is the Schema for the IBMVPCMachinetemplates API
23+
type IBMVPCMachineTemplate struct {
24+
metav1.TypeMeta `json:",inline"`
25+
metav1.ObjectMeta `json:"metadata,omitempty"`
26+
27+
Spec IBMVPCMachineTemplateSpec `json:"spec,omitempty"`
28+
}
29+
30+
// +kubebuilder:object:root=true
31+
32+
// IBMVPCMachineTemplateList contains a list of IBMVPCMachineTemplate
33+
type IBMVPCMachineTemplateList struct {
34+
metav1.TypeMeta `json:",inline"`
35+
metav1.ListMeta `json:"metadata,omitempty"`
36+
Items []IBMVPCMachineTemplate `json:"items"`
37+
}
38+
39+
func init() {
40+
SchemeBuilder.Register(&IBMVPCMachineTemplate{}, &IBMVPCMachineTemplateList{})
41+
}

api/v1alpha4/types.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package v1alpha4
2+
3+
type NetworkInterface struct {
4+
// Subnet ID of the network interface
5+
Subnet string `json:"subnet,omitempty"`
6+
}
7+
8+
type Subnet struct {
9+
Ipv4CidrBlock *string `json:"cidr"`
10+
Name *string `json:"name"`
11+
ID *string `json:"id"`
12+
Zone *string `json:"zone"`
13+
}
14+
15+
type APIEndpoint struct {
16+
Address *string `json:"address"`
17+
FIPID *string `json:"floatingIPID"`
18+
}

0 commit comments

Comments
 (0)