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

feat(RedisCluster): add cloud-control boilerplate #994

Merged
merged 2 commits into from
Feb 3, 2025
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
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,13 @@ resources:
kind: SkrStatus
path: github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1
version: v1beta1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: kyma-project.io
group: cloud-control
kind: RedisCluster
path: github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1
version: v1beta1
version: "3"
149 changes: 149 additions & 0 deletions api/cloud-control/v1beta1/rediscluster_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
Copyright 2023.

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"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type RedisClusterGcp struct {
}

type RedisClusterAzure struct {
}

type RedisClusterAws struct {
}

// +kubebuilder:validation:MinProperties=1
// +kubebuilder:validation:MaxProperties=1
type RedisClusterInfo struct {
// +optional
Gcp *RedisClusterGcp `json:"gcp,omitempty"`

// +optional
Azure *RedisClusterAzure `json:"azure,omitempty"`

// +optional
Aws *RedisClusterAws `json:"aws,omitempty"`
}

// RedisClusterSpec defines the desired state of RedisCluster
type RedisClusterSpec struct {
// +kubebuilder:validation:Required
// +kubebuilder:validation:XValidation:rule=(self == oldSelf), message="RemoteRef is immutable."
RemoteRef RemoteRef `json:"remoteRef"`

// +kubebuilder:validation:Required
// +kubebuilder:validation:XValidation:rule=(size(self.name) > 0), message="IpRange name must not be empty."
IpRange IpRangeRef `json:"ipRange"`

// +kubebuilder:validation:Required
Scope ScopeRef `json:"scope"`

// +kubebuilder:validation:Required
Instance RedisClusterInfo `json:"instance"`
}

// RedisClusterStatus defines the observed state of RedisCluster
type RedisClusterStatus struct {
State StatusState `json:"state,omitempty"`

// List of status conditions to indicate the status of a RedisInstance.
// +optional
// +listType=map
// +listMapKey=type
Conditions []metav1.Condition `json:"conditions"`
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

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

Spec RedisClusterSpec `json:"spec,omitempty"`
Status RedisClusterStatus `json:"status,omitempty"`
}

func (in *RedisCluster) ScopeRef() ScopeRef {
return in.Spec.Scope
}

func (in *RedisCluster) SetScopeRef(scopeRef ScopeRef) {
in.Spec.Scope = scopeRef
}

func (in *RedisCluster) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}

func (in *RedisCluster) State() string {
return string(in.Status.State)
}

func (in *RedisCluster) SetState(v string) {
in.Status.State = StatusState(v)
}

func (in *RedisCluster) GetObjectMeta() *metav1.ObjectMeta {
return &in.ObjectMeta
}

func (in *RedisCluster) CloneForPatchStatus() client.Object {
result := &RedisCluster{
TypeMeta: metav1.TypeMeta{
Kind: "RedisCluster",
APIVersion: GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: in.Namespace,
Name: in.Name,
},
Status: in.Status,
}

if result.Status.Conditions == nil {
result.Status.Conditions = []metav1.Condition{}
}

return result
}

func (in *RedisCluster) SetStatusStateToReady() {
in.Status.State = StateReady
}

func (in *RedisCluster) SetStatusStateToError() {
in.Status.State = StateError
}

// +kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&RedisCluster{}, &RedisClusterList{})
}
175 changes: 175 additions & 0 deletions api/cloud-control/v1beta1/zz_generated.deepcopy.go

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

7 changes: 7 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,13 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "Nuke")
os.Exit(1)
}
if err = cloudcontrolcontroller.SetupRedisClusterReconciler(
mgr,
env,
); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "RedisCluster")
os.Exit(1)
}
//+kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand Down
Loading
Loading