Skip to content

Commit

Permalink
Add IBMPowerVSImage API (kubernetes-sigs#507)
Browse files Browse the repository at this point in the history
Signed-off-by: Prajyot-Parab <[email protected]>
  • Loading branch information
Prajyot-Parab authored Feb 3, 2022
1 parent 3f7b445 commit 97e25d0
Show file tree
Hide file tree
Showing 21 changed files with 1,142 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ COPY api/ api/
COPY controllers/ controllers/
COPY cloud/ cloud/
COPY pkg/ pkg/
COPY util/ util/

# Build
ARG ARCH
Expand Down
3 changes: 3 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@ resources:
- group: infrastructure
kind: IBMPowerVSMachineTemplate
version: v1beta1
- group: infrastructure
kind: IBMPowerVSImage
version: v1beta1
version: "2"
10 changes: 10 additions & 0 deletions api/v1beta1/conditions_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,13 @@ const (
// InstanceReadyCondition reports on current status of the instance. Ready indicates the instance is in a Running state.
InstanceReadyCondition clusterv1.ConditionType = "InstanceReady"
)

const (
// ImageNotReadyReason used when the image is in a queued state.
ImageNotReadyReason = "ImageNotReady"
)

const (
// ImageReadyCondition reports on current status of the image. Ready indicates the image is in a active state.
ImageReadyCondition clusterv1.ConditionType = "ImageReady"
)
113 changes: 113 additions & 0 deletions api/v1beta1/ibmpowervsimage_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
Copyright 2022 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
)

// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

const (
// IBMPowerVSImageFinalizer allows IBMPowerVSImageReconciler to clean up resources associated with IBMPowerVSImage before
// removing it from the apiserver.
IBMPowerVSImageFinalizer = "ibmpowervsimage.infrastructure.cluster.x-k8s.io"
)

// IBMPowerVSImageSpec defines the desired state of IBMPowerVSImage
type IBMPowerVSImageSpec struct {

// ClusterName is the name of the Cluster this object belongs to.
// +kubebuilder:validation:MinLength=1
ClusterName string `json:"clusterName"`

// ServiceInstanceID is the id of the power cloud instance where the image will get imported
ServiceInstanceID string `json:"serviceInstanceID"`

// Cloud Object Storage bucket name; bucket-name[/optional/folder]
Bucket *string `json:"bucket"`

// Cloud Object Storage image filename
Object *string `json:"object"`

// Cloud Object Storage region
Region *string `json:"region"`

// Type of storage, storage pool with the most available space will be selected
// +kubebuilder:default=tier1
// +kubebuilder:validation:Enum=tier1;tier3
// +optional
StorageType string `json:"storageType,omitempty"`
}

// IBMPowerVSImageStatus defines the observed state of IBMPowerVSImage
type IBMPowerVSImageStatus struct {

// Ready is true when the provider resource is ready.
// +optional
Ready bool `json:"ready,omitempty"`

// ImageID is the id of the imported image
ImageID string `json:"imageID,omitempty"`

// ImageState is the status of the imported image
// +optional
ImageState PowerVSImageState `json:"imageState,omitempty"`

// Conditions defines current service state of the IBMPowerVSImage.
// +optional
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:storageversion
// +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.imageState",description="PowerVS image state"
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Image is ready for IBM PowerVS instances"

// IBMPowerVSImage is the Schema for the ibmpowervsimages API
type IBMPowerVSImage struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec IBMPowerVSImageSpec `json:"spec,omitempty"`
Status IBMPowerVSImageStatus `json:"status,omitempty"`
}

// GetConditions returns the observations of the operational state of the IBMPowerVSImage resource.
func (r *IBMPowerVSImage) GetConditions() clusterv1.Conditions {
return r.Status.Conditions
}

// SetConditions sets the underlying service state of the IBMPowerVSImage to the predescribed clusterv1.Conditions.
func (r *IBMPowerVSImage) SetConditions(conditions clusterv1.Conditions) {
r.Status.Conditions = conditions
}

//+kubebuilder:object:root=true

// IBMPowerVSImageList contains a list of IBMPowerVSImage
type IBMPowerVSImageList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []IBMPowerVSImage `json:"items"`
}

func init() {
SchemeBuilder.Register(&IBMPowerVSImage{}, &IBMPowerVSImageList{})
}
65 changes: 65 additions & 0 deletions api/v1beta1/ibmpowervsimage_webhook.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Copyright 2022 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1

import (
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
)

// log is for logging in this package.
var ibmpowervsimagelog = logf.Log.WithName("ibmpowervsimage-resource")

func (r *IBMPowerVSImage) SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(r).
Complete()
}

//+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

var _ webhook.Defaulter = &IBMPowerVSImage{}

// Default implements webhook.Defaulter so a webhook will be registered for the type
func (r *IBMPowerVSImage) Default() {
ibmpowervsimagelog.Info("default", "name", r.Name)
}

// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
//+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

var _ webhook.Validator = &IBMPowerVSImage{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *IBMPowerVSImage) ValidateCreate() error {
ibmpowervsimagelog.Info("validate create", "name", r.Name)
return nil
}

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
func (r *IBMPowerVSImage) ValidateUpdate(old runtime.Object) error {
ibmpowervsimagelog.Info("validate update", "name", r.Name)
return nil
}

// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
func (r *IBMPowerVSImage) ValidateDelete() error {
ibmpowervsimagelog.Info("validate delete", "name", r.Name)
return nil
}
11 changes: 11 additions & 0 deletions api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ var (
PowerVSInstanceStateREBOOT = PowerVSInstanceState("REBOOT")
)

// PowerVSImageState describes the state of an IBM Power VS image.
type PowerVSImageState string

var (
// PowerVSImageStateACTIVE is the string representing an image in a active state.
PowerVSImageStateACTIVE = PowerVSImageState("active")

// PowerVSInstanceStateQue is the string representing an image in a queued state.
PowerVSInstanceStateQue = PowerVSImageState("queued")
)

// NetworkInterface holds the network interface information like subnet id.
type NetworkInterface struct {
// Subnet ID of the network interface
Expand Down
111 changes: 111 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 97e25d0

Please sign in to comment.