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: Cceenfsvolume #1009

Merged
merged 4 commits into from
Feb 14, 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
85 changes: 83 additions & 2 deletions api/cloud-resources/v1beta1/cceenfsvolume_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1beta1

import (
featuretypes "github.com/kyma-project/cloud-manager/pkg/feature/types"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand All @@ -28,6 +29,7 @@ type CceeNfsVolumeSpec struct {
IpRange IpRangeRef `json:"ipRange"`

// +kubebuilder:validation:Required
// +kubebuilder:validation:XValidation:rule=(self > 0), message="The field capacityGb must be greater than zero"
CapacityGb int `json:"capacityGb"`

// +optional
Expand Down Expand Up @@ -55,7 +57,7 @@ type CceeNfsVolumeStatus struct {
// +optional
// +listType=map
// +listMapKey=type
Conditions []metav1.Condition `json:"conditions,omitempty"`
Conditions []metav1.Condition `json:"conditions"`

// +optional
State string `json:"state,omitempty"`
Expand All @@ -74,6 +76,70 @@ type CceeNfsVolume struct {
Status CceeNfsVolumeStatus `json:"status,omitempty"`
}

func (in *CceeNfsVolume) GetPVName() string {
if in.Spec.PersistentVolume != nil && in.Spec.PersistentVolume.Name != "" {
return in.Spec.PersistentVolume.Name
}
return in.Status.Id
}

func (in *CceeNfsVolume) GetPVLabels() map[string]string {
result := make(map[string]string, 10)
if in.Spec.PersistentVolume != nil && in.Spec.PersistentVolume.Labels != nil {
for k, v := range in.Spec.PersistentVolume.Labels {
result[k] = v
}
}
result[LabelNfsVolName] = in.Name
result[LabelNfsVolNS] = in.Namespace
result[LabelCloudManaged] = "true"

return result
}

func (in *CceeNfsVolume) GetPVAnnotations() map[string]string {
if in.Spec.PersistentVolume == nil {
return nil
}
result := make(map[string]string, len(in.Spec.PersistentVolume.Annotations))
for k, v := range in.Spec.PersistentVolume.Annotations {
result[k] = v
}
return result
}

func (in *CceeNfsVolume) GetPVCName() string {
if in.Spec.PersistentVolumeClaim != nil && in.Spec.PersistentVolumeClaim.Name != "" {
return in.Spec.PersistentVolumeClaim.Name
}
return in.Name
}

func (in *CceeNfsVolume) GetPVCLabels() map[string]string {
result := make(map[string]string, 10)
if in.Spec.PersistentVolumeClaim != nil && in.Spec.PersistentVolumeClaim.Labels != nil {
for k, v := range in.Spec.PersistentVolumeClaim.Labels {
result[k] = v
}
}
result[LabelNfsVolName] = in.Name
result[LabelNfsVolNS] = in.Namespace
result[LabelCloudManaged] = "true"

return result
}

func (in *CceeNfsVolume) GetPVCAnnotations() map[string]string {
if in.Spec.PersistentVolumeClaim == nil {
return nil
}
result := make(map[string]string, len(in.Spec.PersistentVolumeClaim.Annotations))
for k, v := range in.Spec.PersistentVolumeClaim.Annotations {
result[k] = v
}
return result
}

func (in *CceeNfsVolume) Conditions() *[]metav1.Condition {
return &in.Status.Conditions
}
Expand Down Expand Up @@ -103,7 +169,7 @@ func (in *CceeNfsVolume) SetState(v string) {
}

func (in *CceeNfsVolume) CloneForPatchStatus() client.Object {
return &CceeNfsVolume{
result := &CceeNfsVolume{
TypeMeta: metav1.TypeMeta{
Kind: "CceeNfsVolume",
APIVersion: GroupVersion.String(),
Expand All @@ -114,6 +180,21 @@ func (in *CceeNfsVolume) CloneForPatchStatus() client.Object {
},
Status: in.Status,
}
if result.Status.Conditions == nil {
result.Status.Conditions = []metav1.Condition{}
}
return result
}

func (in *CceeNfsVolume) DeriveStateFromConditions() (changed bool) {
oldState := in.Status.State
if meta.FindStatusCondition(in.Status.Conditions, ConditionTypeReady) != nil {
in.Status.State = StateReady
}
if meta.FindStatusCondition(in.Status.Conditions, ConditionTypeError) != nil {
in.Status.State = StateError
}
return in.Status.State != oldState
}

// +kubebuilder:object:root=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ spec:
properties:
capacityGb:
type: integer
x-kubernetes-validations:
- message: The field capacityGb must be greater than zero
rule: (self > 0)
ipRange:
properties:
name:
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/cloud-resources/awsnfsvolume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ var _ = Describe("Feature: SKR AwsNfsVolume", func() {
By("When AwsNfsVolume is deleted", func() {
Eventually(Delete).
WithArguments(infra.Ctx(), infra.SKR().Client(), awsNfsVolume).
Should(Succeed(), "failed deleting PV")
Should(Succeed(), "failed deleting AwsNfsVolume")
})

By("Then SKR AwsNfsVolume has Deleting state", func() {
Expand Down
Loading
Loading