forked from kubernetes-sigs/cluster-api-provider-ibmcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IBMPowerVSImage API (kubernetes-sigs#507)
Signed-off-by: Prajyot-Parab <[email protected]>
- Loading branch information
1 parent
3f7b445
commit 97e25d0
Showing
21 changed files
with
1,142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.