Skip to content

Commit 97e25d0

Browse files
Add IBMPowerVSImage API (#507)
Signed-off-by: Prajyot-Parab <[email protected]>
1 parent 3f7b445 commit 97e25d0

21 files changed

+1142
-0
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ COPY api/ api/
3232
COPY controllers/ controllers/
3333
COPY cloud/ cloud/
3434
COPY pkg/ pkg/
35+
COPY util/ util/
3536

3637
# Build
3738
ARG ARCH

PROJECT

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ resources:
3737
- group: infrastructure
3838
kind: IBMPowerVSMachineTemplate
3939
version: v1beta1
40+
- group: infrastructure
41+
kind: IBMPowerVSImage
42+
version: v1beta1
4043
version: "2"

api/v1beta1/conditions_consts.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,13 @@ const (
4141
// InstanceReadyCondition reports on current status of the instance. Ready indicates the instance is in a Running state.
4242
InstanceReadyCondition clusterv1.ConditionType = "InstanceReady"
4343
)
44+
45+
const (
46+
// ImageNotReadyReason used when the image is in a queued state.
47+
ImageNotReadyReason = "ImageNotReady"
48+
)
49+
50+
const (
51+
// ImageReadyCondition reports on current status of the image. Ready indicates the image is in a active state.
52+
ImageReadyCondition clusterv1.ConditionType = "ImageReady"
53+
)
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
Copyright 2022 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 v1beta1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
22+
)
23+
24+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
25+
26+
const (
27+
// IBMPowerVSImageFinalizer allows IBMPowerVSImageReconciler to clean up resources associated with IBMPowerVSImage before
28+
// removing it from the apiserver.
29+
IBMPowerVSImageFinalizer = "ibmpowervsimage.infrastructure.cluster.x-k8s.io"
30+
)
31+
32+
// IBMPowerVSImageSpec defines the desired state of IBMPowerVSImage
33+
type IBMPowerVSImageSpec struct {
34+
35+
// ClusterName is the name of the Cluster this object belongs to.
36+
// +kubebuilder:validation:MinLength=1
37+
ClusterName string `json:"clusterName"`
38+
39+
// ServiceInstanceID is the id of the power cloud instance where the image will get imported
40+
ServiceInstanceID string `json:"serviceInstanceID"`
41+
42+
// Cloud Object Storage bucket name; bucket-name[/optional/folder]
43+
Bucket *string `json:"bucket"`
44+
45+
// Cloud Object Storage image filename
46+
Object *string `json:"object"`
47+
48+
// Cloud Object Storage region
49+
Region *string `json:"region"`
50+
51+
// Type of storage, storage pool with the most available space will be selected
52+
// +kubebuilder:default=tier1
53+
// +kubebuilder:validation:Enum=tier1;tier3
54+
// +optional
55+
StorageType string `json:"storageType,omitempty"`
56+
}
57+
58+
// IBMPowerVSImageStatus defines the observed state of IBMPowerVSImage
59+
type IBMPowerVSImageStatus struct {
60+
61+
// Ready is true when the provider resource is ready.
62+
// +optional
63+
Ready bool `json:"ready,omitempty"`
64+
65+
// ImageID is the id of the imported image
66+
ImageID string `json:"imageID,omitempty"`
67+
68+
// ImageState is the status of the imported image
69+
// +optional
70+
ImageState PowerVSImageState `json:"imageState,omitempty"`
71+
72+
// Conditions defines current service state of the IBMPowerVSImage.
73+
// +optional
74+
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
75+
}
76+
77+
//+kubebuilder:object:root=true
78+
//+kubebuilder:subresource:status
79+
//+kubebuilder:storageversion
80+
// +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.imageState",description="PowerVS image state"
81+
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Image is ready for IBM PowerVS instances"
82+
83+
// IBMPowerVSImage is the Schema for the ibmpowervsimages API
84+
type IBMPowerVSImage struct {
85+
metav1.TypeMeta `json:",inline"`
86+
metav1.ObjectMeta `json:"metadata,omitempty"`
87+
88+
Spec IBMPowerVSImageSpec `json:"spec,omitempty"`
89+
Status IBMPowerVSImageStatus `json:"status,omitempty"`
90+
}
91+
92+
// GetConditions returns the observations of the operational state of the IBMPowerVSImage resource.
93+
func (r *IBMPowerVSImage) GetConditions() clusterv1.Conditions {
94+
return r.Status.Conditions
95+
}
96+
97+
// SetConditions sets the underlying service state of the IBMPowerVSImage to the predescribed clusterv1.Conditions.
98+
func (r *IBMPowerVSImage) SetConditions(conditions clusterv1.Conditions) {
99+
r.Status.Conditions = conditions
100+
}
101+
102+
//+kubebuilder:object:root=true
103+
104+
// IBMPowerVSImageList contains a list of IBMPowerVSImage
105+
type IBMPowerVSImageList struct {
106+
metav1.TypeMeta `json:",inline"`
107+
metav1.ListMeta `json:"metadata,omitempty"`
108+
Items []IBMPowerVSImage `json:"items"`
109+
}
110+
111+
func init() {
112+
SchemeBuilder.Register(&IBMPowerVSImage{}, &IBMPowerVSImageList{})
113+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
Copyright 2022 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 v1beta1
18+
19+
import (
20+
"k8s.io/apimachinery/pkg/runtime"
21+
ctrl "sigs.k8s.io/controller-runtime"
22+
logf "sigs.k8s.io/controller-runtime/pkg/log"
23+
"sigs.k8s.io/controller-runtime/pkg/webhook"
24+
)
25+
26+
// log is for logging in this package.
27+
var ibmpowervsimagelog = logf.Log.WithName("ibmpowervsimage-resource")
28+
29+
func (r *IBMPowerVSImage) SetupWebhookWithManager(mgr ctrl.Manager) error {
30+
return ctrl.NewWebhookManagedBy(mgr).
31+
For(r).
32+
Complete()
33+
}
34+
35+
//+kubebuilder:webhook:path=/mutate-infrastructure-cluster-x-k8s-io-v1beta1-ibmpowervsimage,mutating=true,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=ibmpowervsimages,verbs=create;update,versions=v1beta1,name=mibmpowervsimage.kb.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
36+
37+
var _ webhook.Defaulter = &IBMPowerVSImage{}
38+
39+
// Default implements webhook.Defaulter so a webhook will be registered for the type
40+
func (r *IBMPowerVSImage) Default() {
41+
ibmpowervsimagelog.Info("default", "name", r.Name)
42+
}
43+
44+
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
45+
//+kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1beta1-ibmpowervsimage,mutating=false,failurePolicy=fail,groups=infrastructure.cluster.x-k8s.io,resources=ibmpowervsimages,versions=v1beta1,name=vibmpowervsimage.kb.io,sideEffects=None,admissionReviewVersions=v1;v1beta1
46+
47+
var _ webhook.Validator = &IBMPowerVSImage{}
48+
49+
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
50+
func (r *IBMPowerVSImage) ValidateCreate() error {
51+
ibmpowervsimagelog.Info("validate create", "name", r.Name)
52+
return nil
53+
}
54+
55+
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
56+
func (r *IBMPowerVSImage) ValidateUpdate(old runtime.Object) error {
57+
ibmpowervsimagelog.Info("validate update", "name", r.Name)
58+
return nil
59+
}
60+
61+
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
62+
func (r *IBMPowerVSImage) ValidateDelete() error {
63+
ibmpowervsimagelog.Info("validate delete", "name", r.Name)
64+
return nil
65+
}

api/v1beta1/types.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ var (
3333
PowerVSInstanceStateREBOOT = PowerVSInstanceState("REBOOT")
3434
)
3535

36+
// PowerVSImageState describes the state of an IBM Power VS image.
37+
type PowerVSImageState string
38+
39+
var (
40+
// PowerVSImageStateACTIVE is the string representing an image in a active state.
41+
PowerVSImageStateACTIVE = PowerVSImageState("active")
42+
43+
// PowerVSInstanceStateQue is the string representing an image in a queued state.
44+
PowerVSInstanceStateQue = PowerVSImageState("queued")
45+
)
46+
3647
// NetworkInterface holds the network interface information like subnet id.
3748
type NetworkInterface struct {
3849
// Subnet ID of the network interface

api/v1beta1/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)