Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Types for Bucket, BucketClass and BucketPool #593

Merged
merged 5 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions api/storage/v1alpha1/bucket_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* Copyright (c) 2021 by the OnMetal 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 v1alpha1

import (
commonv1alpha1 "github.com/onmetal/onmetal-api/api/common/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
)

// BucketGK is a helper to easily access the GroupKind information of a Bucket
var BucketGK = schema.GroupKind{
Group: SchemeGroupVersion.Group,
Kind: "Bucket",
}

// BucketSpec defines the desired state of Bucket
type BucketSpec struct {
// BucketClassRef is the BucketClass of a bucket
// If empty, an external controller has to provision the bucket.
BucketClassRef *corev1.LocalObjectReference `json:"bucketClassRef,omitempty"`
// BucketPoolSelector selects a suitable BucketPoolRef by the given labels.
BucketPoolSelector map[string]string `json:"bucketPoolSelector,omitempty"`
// BucketPoolRef indicates which BucketPool to use for a bucket.
// If unset, the scheduler will figure out a suitable BucketPoolRef.
BucketPoolRef *corev1.LocalObjectReference `json:"bucketPoolRef,omitempty"`
// Tolerations define tolerations the Bucket has. Only any BucketPool whose taints
// covered by Tolerations will be considered to host the Bucket.
Tolerations []commonv1alpha1.Toleration `json:"tolerations,omitempty"`
}

// BucketAccess represents information on how to access a bucket.
type BucketAccess struct {
// SecretRef references the Secret containing the access credentials to consume a Bucket.
SecretRef *corev1.LocalObjectReference `json:"secretRef,omitempty"`
// Endpoint defines address of the Bucket REST-API.
Endpoint string `json:"endpoint"`
}

// BucketStatus defines the observed state of Bucket
type BucketStatus struct {
// State represents the infrastructure state of a Bucket.
State BucketState `json:"state,omitempty"`
// LastStateTransitionTime is the last time the State transitioned between values.
LastStateTransitionTime *metav1.Time `json:"lastStateTransitionTime,omitempty"`

// Access specifies how to access a Bucket.
// This is set by the bucket provider when the bucket is provisioned.
Access *BucketAccess `json:"access,omitempty"`

// Conditions are the conditions of a bucket.
Conditions []BucketCondition `json:"conditions,omitempty"`
lukasfrank marked this conversation as resolved.
Show resolved Hide resolved
}

// BucketConditionType is a type a BucketCondition can have.
type BucketConditionType string

// BucketCondition is one of the conditions of a bucket.
type BucketCondition struct {
// Type is the type of the condition.
Type BucketConditionType `json:"type"`
// Status is the status of the condition.
Status corev1.ConditionStatus `json:"status"`
// Reason is a machine-readable indication of why the condition is in a certain state.
Reason string `json:"reason,omitempty"`
// Message is a human-readable explanation of why the condition has a certain reason / state.
Message string `json:"message,omitempty"`
// ObservedGeneration represents the .metadata.generation that the condition was set based upon.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// LastTransitionTime is the last time the status of a condition has transitioned from one state to another.
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
}

// BucketState represents the infrastructure state of a Bucket.
type BucketState string

const (
// BucketStatePending reports whether a Bucket is about to be ready.
BucketStatePending BucketState = "Pending"
// BucketStateAvailable reports whether a Bucket is available to be used.
BucketStateAvailable BucketState = "Available"
// BucketStateError reports that a Bucket is in an error state.
BucketStateError BucketState = "Error"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +genclient

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

Spec BucketSpec `json:"spec,omitempty"`
Status BucketStatus `json:"status,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

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

// BucketTemplateSpec is the specification of a Bucket template.
type BucketTemplateSpec struct {
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec BucketSpec `json:"spec,omitempty"`
}
48 changes: 48 additions & 0 deletions api/storage/v1alpha1/bucketclass_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (c) 2021 by the OnMetal 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 v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var (
// BucketClassFinalizer is the finalizer for BucketClass.
BucketClassFinalizer = SchemeGroupVersion.Group + "/bucketclass"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +genclient
// +genclient:nonNamespaced

// BucketClass is the Schema for the bucketclasses API
type BucketClass struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
// Capabilities describes the capabilities of a BucketClass.
Capabilities corev1.ResourceList `json:"capabilities,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// BucketClassList contains a list of BucketClass
type BucketClassList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []BucketClass `json:"items"`
}
71 changes: 71 additions & 0 deletions api/storage/v1alpha1/bucketpool_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2021 by the OnMetal 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 v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

commonv1alpha1 "github.com/onmetal/onmetal-api/api/common/v1alpha1"
)

// BucketPoolSpec defines the desired state of BucketPool
type BucketPoolSpec struct {
// ProviderID identifies the BucketPool on provider side.
ProviderID string `json:"providerID"`
// Taints of the BucketPool. Only Buckets who tolerate all the taints
// will land in the BucketPool.
Taints []commonv1alpha1.Taint `json:"taints,omitempty"`
}

// BucketPoolStatus defines the observed state of BucketPool
type BucketPoolStatus struct {
// State represents the infrastructure state of a BucketPool.
State BucketPoolState `json:"state,omitempty"`
// AvailableBucketClasses list the references of any supported BucketClass of this pool
AvailableBucketClasses []corev1.LocalObjectReference `json:"availableBucketClasses,omitempty"`
}

type BucketPoolState string

const (
BucketPoolStateAvailable BucketPoolState = "Available"
BucketPoolStatePending BucketPoolState = "Pending"
BucketPoolStateUnavailable BucketPoolState = "Unavailable"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +genclient
// +genclient:nonNamespaced

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

Spec BucketPoolSpec `json:"spec,omitempty"`
Status BucketPoolStatus `json:"status,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// BucketPoolList contains a list of BucketPool
type BucketPoolList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []BucketPool `json:"items"`
}
10 changes: 10 additions & 0 deletions api/storage/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@

package v1alpha1

import corev1 "k8s.io/api/core/v1"

const (
VolumeVolumePoolRefNameField = "spec.volumePoolRef.name"
BucketBucketPoolRefNameField = "spec.bucketPoolRef.name"
)

const (
// ResourceTPS defines max throughput per second. (e.g. 1Gi)
ResourceTPS corev1.ResourceName = "tps"
// ResourceIOPS defines max IOPS in input/output operations per second.
ResourceIOPS corev1.ResourceName = "iops"
)
6 changes: 6 additions & 0 deletions api/storage/v1alpha1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ func addKnownTypes(scheme *runtime.Scheme) error {
&VolumePoolList{},
&Volume{},
&VolumeList{},
&BucketClass{},
&BucketClassList{},
&BucketPool{},
&BucketPoolList{},
&Bucket{},
&BucketList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
Expand Down
7 changes: 0 additions & 7 deletions api/storage/v1alpha1/volumeclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
// ResourceTPS defines max throughput per second. (e.g. 1Gi)
ResourceTPS corev1.ResourceName = "tps"
// ResourceIOPS defines max IOPS in input/output operations per second.
ResourceIOPS corev1.ResourceName = "iops"
)

var (
// VolumeClassFinalizer is the finalizer for VolumeClass.
VolumeClassFinalizer = SchemeGroupVersion.Group + "/volumeclass"
Expand Down
Loading