Skip to content

Commit

Permalink
feat: preventing zombie filestore backups and patching status instead…
Browse files Browse the repository at this point in the history
… of update
  • Loading branch information
abalaie committed Sep 4, 2024
1 parent f49cbf3 commit f6ca8e5
Show file tree
Hide file tree
Showing 58 changed files with 320 additions and 178 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ jobs:
strategy:
matrix:
ipRangeAutomaticCidrAllocation: [ "false", "true" ]
gcpNfsVolumeAutomaticLocationAllocation: [ "false", "true" ]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand All @@ -22,6 +23,7 @@ jobs:
- name: Build and test
env:
FF_IP_RANGE_AUTOMATIC_CIDR_ALLOCATION: ${{ matrix.ipRangeAutomaticCidrAllocation }}
FF_GCP_NFS_VOLUME_AUTOMATIC_LOCATION_ALLOCATION: ${{ matrix.gcpNfsVolumeAutomaticLocationAllocation }}
run: |
./config/sync.sh
go mod tidy
Expand Down
15 changes: 15 additions & 0 deletions api/cloud-resources/v1beta1/gcpnfsbackupschedule_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
featuretypes "github.com/kyma-project/cloud-manager/pkg/feature/types"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand Down Expand Up @@ -280,3 +281,17 @@ type GcpNfsBackupScheduleList struct {
func init() {
SchemeBuilder.Register(&GcpNfsBackupSchedule{}, &GcpNfsBackupScheduleList{})
}

func (sc *GcpNfsBackupSchedule) CloneForPatchStatus() client.Object {
return &GcpNfsBackupSchedule{
TypeMeta: metav1.TypeMeta{
Kind: "GcpNfsBackupSchedule",
APIVersion: GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: sc.Namespace,
Name: sc.Name,
},
Status: sc.Status,
}
}
20 changes: 16 additions & 4 deletions api/cloud-resources/v1beta1/gcpnfsvolumebackup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
featuretypes "github.com/kyma-project/cloud-manager/pkg/feature/types"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type GcpNfsBackupState string
Expand All @@ -32,9 +33,6 @@ const (
// GcpNfsBackupError signifies the backup operation resulted in error.
GcpNfsBackupError GcpNfsBackupState = "Error"

// GcpNfsBackupProcessing signifies backup operation is in-progress.
GcpNfsBackupProcessing GcpNfsBackupState = "Processing"

// GcpNfsBackupCreating signifies backup create operation is in-progress.
GcpNfsBackupCreating GcpNfsBackupState = "Creating"

Expand Down Expand Up @@ -62,7 +60,7 @@ type GcpNfsVolumeRef struct {
Namespace string `json:"namespace,omitempty"`
}

func (v GcpNfsVolumeRef) ToNamespacedName(fallbackNamespace string) types.NamespacedName {
func (v *GcpNfsVolumeRef) ToNamespacedName(fallbackNamespace string) types.NamespacedName {
ns := v.Namespace
if len(ns) == 0 {
ns = fallbackNamespace
Expand Down Expand Up @@ -158,3 +156,17 @@ type GcpNfsVolumeBackupList struct {
func init() {
SchemeBuilder.Register(&GcpNfsVolumeBackup{}, &GcpNfsVolumeBackupList{})
}

func (in *GcpNfsVolumeBackup) CloneForPatchStatus() client.Object {
return &GcpNfsVolumeBackup{
TypeMeta: metav1.TypeMeta{
Kind: "GcpNfsVolumeBackup",
APIVersion: GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: in.Namespace,
Name: in.Name,
},
Status: in.Status,
}
}
17 changes: 16 additions & 1 deletion api/cloud-resources/v1beta1/gcpnfsvolumerestore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
featuretypes "github.com/kyma-project/cloud-manager/pkg/feature/types"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

type GcpNfsVolumeBackupRef struct {
Expand All @@ -31,7 +32,7 @@ type GcpNfsVolumeBackupRef struct {
Namespace string `json:"namespace"`
}

func (v GcpNfsVolumeBackupRef) ToNamespacedName(fallbackNamespace string) types.NamespacedName {
func (v *GcpNfsVolumeBackupRef) ToNamespacedName(fallbackNamespace string) types.NamespacedName {
ns := v.Namespace
if len(ns) == 0 {
ns = fallbackNamespace
Expand Down Expand Up @@ -125,3 +126,17 @@ type GcpNfsVolumeRestoreList struct {
func init() {
SchemeBuilder.Register(&GcpNfsVolumeRestore{}, &GcpNfsVolumeRestoreList{})
}

func (in *GcpNfsVolumeRestore) CloneForPatchStatus() client.Object {
return &GcpNfsVolumeRestore{
TypeMeta: metav1.TypeMeta{
Kind: "GcpNfsVolumeRestore",
APIVersion: GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Namespace: in.Namespace,
Name: in.Name,
},
Status: in.Status,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ var _ = Describe("Feature: SKR GcpNfsBackupSchedule", func() {
timeout = time.Second * 20
)
now := time.Now().UTC()
skrIpRangeName := "gcp-iprange-1"
skrNfsVolumeName := "gcp-nfs-1"
skrIpRangeName := "gcp-iprange-1-bs"
skrNfsVolumeName := "gcp-nfs-1-bs"
skrNfsVolume := &cloudresourcesv1beta1.GcpNfsVolume{}
scope := &cloudcontrolv1beta1.Scope{}

Expand Down Expand Up @@ -83,7 +83,7 @@ var _ = Describe("Feature: SKR GcpNfsBackupSchedule", func() {
nfsBackupHourlySchedule := "0 * * * *"
nfsBackupLocation := "us-west1"

nfsBackup1Name := "gcp-nfs-backup-1"
nfsBackup1Name := "gcp-nfs-backup-1-bs"

expectedTimes := []time.Time{
time.Date(now.Year(), now.Month(), now.Day(), now.Hour()+1, 0, 0, 0, now.Location()).UTC(),
Expand Down
60 changes: 35 additions & 25 deletions internal/controller/cloud-resources/gcpnfsvolume_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cloudresources

import (
"context"
"fmt"
"os"
"github.com/kyma-project/cloud-manager/pkg/feature"
"time"

cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1"
Expand All @@ -26,14 +27,19 @@ var _ = Describe("Feature: SKR GcpNfsVolume", func() {
timeout = time.Second * 20
)

skrIpRangeName := "gcp-iprange-1"
skrIpRangeName := "gcp-iprange-1-v"
skrIpRange := &cloudresourcesv1beta1.IpRange{}
kcpIpRangeName := "513f20b4-7b73-4246-9397-f8dd55344479"
kcpIpRange := &cloudcontrolv1beta1.IpRange{}

shouldSkipIfGcpNfsVolumeAutomaticLocationAllocationDisabled := func() (bool, string) {
if feature.GcpNfsVolumeAutomaticLocationAllocation.Value(context.Background()) {
return false, ""
}
return true, "gcpNfsVolumeAutomaticLocationAllocation is disabled"
}

BeforeEach(func() {
err := os.Unsetenv("FF_GCP_NFS_VOLUME_AUTOMATIC_LOCATION_ALLOCATION")
Expect(err).ToNot(HaveOccurred())
By("And Given SKR namespace exists", func() {
//Create namespace if it doesn't exist.
Eventually(CreateNamespace).
Expand Down Expand Up @@ -100,9 +106,9 @@ var _ = Describe("Feature: SKR GcpNfsVolume", func() {
pv := &corev1.PersistentVolume{}

gcpNfsVolumeName := "gcp-nfs-volume-1"
nfsIpAddress := "10.11.12.14"
nfsIpAddress := "10.11.12.11"
pvSpec := &cloudresourcesv1beta1.GcpNfsVolumePvSpec{
Name: "gcp-nfs-pv",
Name: "gcp-nfs-pv-1",
Labels: map[string]string{
"app": "gcp-nfs",
},
Expand Down Expand Up @@ -301,7 +307,7 @@ var _ = Describe("Feature: SKR GcpNfsVolume", func() {
pv := &corev1.PersistentVolume{}

gcpNfsVolumeName := "gcp-nfs-volume-2"
nfsIpAddress := "10.11.12.16"
nfsIpAddress := "10.11.12.12"
updatedCapacityGb := 1024

prevPv := &corev1.PersistentVolume{}
Expand Down Expand Up @@ -551,7 +557,7 @@ var _ = Describe("Feature: SKR GcpNfsVolume", func() {
pvc := &corev1.PersistentVolumeClaim{}

gcpNfsVolumeName := "gcp-nfs-volume-3"
nfsIpAddress := "10.11.12.16"
nfsIpAddress := "10.11.12.13"

BeforeEach(func() {
By("And Given SKR GcpNfsVolume exists", func() {
Expand Down Expand Up @@ -678,14 +684,12 @@ var _ = Describe("Feature: SKR GcpNfsVolume", func() {
kcpNfsInstance := &cloudcontrolv1beta1.NfsInstance{}
pv := &corev1.PersistentVolume{}
scope := &cloudcontrolv1beta1.Scope{}
err := os.Setenv("FF_GCP_NFS_VOLUME_AUTOMATIC_LOCATION_ALLOCATION", "true")
Expect(err).ToNot(HaveOccurred())
gcpNfsVolumeName := "gcp-nfs-volume-4"
nfsIpAddress := "10.11.12.14"
pvSpec := &cloudresourcesv1beta1.GcpNfsVolumePvSpec{
Name: "gcp-nfs-pv-3",
Name: "gcp-nfs-pv-4",
Labels: map[string]string{
"app": "gcp-nfs-3",
"app": "gcp-nfs-4",
},
Annotations: map[string]string{
"volume": "gcp-nfs-volume-4",
Expand All @@ -694,7 +698,7 @@ var _ = Describe("Feature: SKR GcpNfsVolume", func() {

pvc := &corev1.PersistentVolumeClaim{}
pvcSpec := &cloudresourcesv1beta1.GcpNfsVolumePvcSpec{
Name: "gcp-nfs-pvc-3",
Name: "gcp-nfs-pvc-4",
Labels: map[string]string{
"foo": "bar",
},
Expand All @@ -703,6 +707,10 @@ var _ = Describe("Feature: SKR GcpNfsVolume", func() {
},
}
BeforeEach(func() {
shouldSkip, msg := shouldSkipIfGcpNfsVolumeAutomaticLocationAllocationDisabled()
if shouldSkip {
Skip(msg)
}
By("Given KCP Scope exists", func() {

// Given Scope exists
Expand All @@ -725,7 +733,7 @@ var _ = Describe("Feature: SKR GcpNfsVolume", func() {
infra.Ctx(), infra.SKR().Client(), gcpNfsVolume,
WithName(gcpNfsVolumeName),
WithGcpNfsVolumeIpRange(skrIpRange.Name),
WithGcpNfsVolumeLocation(""),
WithGcpNfsVolumeSpecLocation(""),
WithPvSpec(pvSpec),
WithPvcSpec(pvcSpec),
).
Expand Down Expand Up @@ -898,18 +906,16 @@ var _ = Describe("Feature: SKR GcpNfsVolume", func() {
kcpNfsInstance := &cloudcontrolv1beta1.NfsInstance{}
pv := &corev1.PersistentVolume{}
scope := &cloudcontrolv1beta1.Scope{}
err := os.Setenv("FF_GCP_NFS_VOLUME_AUTOMATIC_LOCATION_ALLOCATION", "true")
Expect(err).ToNot(HaveOccurred())

gcpNfsVolumeName := "gcp-nfs-volume-5"
nfsIpAddress := "10.11.12.16"
nfsIpAddress := "10.11.12.15"
updatedCapacityGb := 1024

prevPv := &corev1.PersistentVolume{}
pvSpec := &cloudresourcesv1beta1.GcpNfsVolumePvSpec{
Name: "gcp-nfs-pv-4",
Name: "gcp-nfs-pv-5",
Labels: map[string]string{
"app": "gcp-nfs-4",
"app": "gcp-nfs-5",
},
Annotations: map[string]string{
"volume": "gcp-nfs-volume-5",
Expand All @@ -918,7 +924,7 @@ var _ = Describe("Feature: SKR GcpNfsVolume", func() {

pvc := &corev1.PersistentVolumeClaim{}
prevPvcSpec := &cloudresourcesv1beta1.GcpNfsVolumePvcSpec{
Name: "gcp-nfs-pvc-4",
Name: "gcp-nfs-pvc-5",
Labels: map[string]string{
"foo": "bar",
},
Expand All @@ -927,7 +933,7 @@ var _ = Describe("Feature: SKR GcpNfsVolume", func() {
},
}
pvcSpec := &cloudresourcesv1beta1.GcpNfsVolumePvcSpec{
Name: "gcp-nfs-pvc-4",
Name: "gcp-nfs-pvc-5",
Labels: map[string]string{
"foo": "bar-changed",
"foo2": "bar2",
Expand All @@ -939,6 +945,10 @@ var _ = Describe("Feature: SKR GcpNfsVolume", func() {
}

BeforeEach(func() {
shouldSkip, msg := shouldSkipIfGcpNfsVolumeAutomaticLocationAllocationDisabled()
if shouldSkip {
Skip(msg)
}
By("Given KCP Scope exists", func() {

// Given Scope exists
Expand Down Expand Up @@ -1022,7 +1032,6 @@ var _ = Describe("Feature: SKR GcpNfsVolume", func() {
})

It("When SKR GcpNfsVolume Update is called ", func() {

Eventually(Update).
WithArguments(
infra.Ctx(), infra.SKR().Client(), gcpNfsVolume,
Expand Down Expand Up @@ -1165,13 +1174,15 @@ var _ = Describe("Feature: SKR GcpNfsVolume", func() {
pv := &corev1.PersistentVolume{}
pvc := &corev1.PersistentVolumeClaim{}
scope := &cloudcontrolv1beta1.Scope{}
err := os.Setenv("FF_GCP_NFS_VOLUME_AUTOMATIC_LOCATION_ALLOCATION", "true")
Expect(err).ToNot(HaveOccurred())

gcpNfsVolumeName := "gcp-nfs-volume-6"
nfsIpAddress := "10.11.12.16"

BeforeEach(func() {
shouldSkip, msg := shouldSkipIfGcpNfsVolumeAutomaticLocationAllocationDisabled()
if shouldSkip {
Skip(msg)
}
By("Given KCP Scope exists", func() {

// Given Scope exists
Expand Down Expand Up @@ -1253,7 +1264,6 @@ var _ = Describe("Feature: SKR GcpNfsVolume", func() {
})
})
It("When SKR GcpNfsVolume Delete is called ", func() {

//Delete SKR GcpNfsVolume
Eventually(Delete).
WithArguments(
Expand Down
Loading

0 comments on commit f6ca8e5

Please sign in to comment.