Skip to content

Commit a019603

Browse files
authored
Change GetAll CRD API to return a Map with keys as CRD name (#1024)
* changed the key for the GetAll CRD API to use name of the CRD instead of Kind * corrected linting errors as highlighted by the IDE
1 parent c083042 commit a019603

File tree

6 files changed

+31
-29
lines changed

6 files changed

+31
-29
lines changed

api/core/crds/crd.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,18 @@ var (
2020
)
2121

2222
const (
23-
// KindEtcd is the kind of the etcd CRD.
24-
KindEtcd = "Etcd"
25-
// KindEtcdCopyBackupsTask is the kind of the etcd-copy-backup-task CRD.
26-
KindEtcdCopyBackupsTask = "EtcdCopyBackupsTask"
23+
// ResourceNameEtcd is the name of the etcd CRD.
24+
ResourceNameEtcd = "etcds.druid.gardener.cloud"
25+
// ResourceNameEtcdCopyBackupsTask is the name of the etcd-copy-backup-task CRD.
26+
ResourceNameEtcdCopyBackupsTask = "etcdcopybackupstasks.druid.gardener.cloud"
2727
)
2828

2929
// GetAll returns all CRDs for the given k8s version.
30+
// The function will return a map with the CRD name as key and the CRD content as value.
3031
// There are currently two sets of CRDs maintained.
3132
// 1. One set is for Kubernetes version 1.29 and above. These CRDs contain embedded CEL validation expressions. CEL expressions are only GA since Kubernetes 1.29 onwards.
3233
// 2. The other set is for Kubernetes versions below 1.29. These CRDs do not contain embedded CEL validation expressions.
34+
// If there are any errors in parsing the k8s version, the function will return an error.
3335
func GetAll(k8sVersion string) (map[string]string, error) {
3436
k8sVersionAbove129, err := IsK8sVersionEqualToOrAbove129(k8sVersion)
3537
if err != nil {
@@ -42,8 +44,8 @@ func GetAll(k8sVersion string) (map[string]string, error) {
4244
selectedEtcdCRD = etcdCRDWithoutCEL
4345
}
4446
return map[string]string{
45-
KindEtcd: selectedEtcdCRD,
46-
KindEtcdCopyBackupsTask: etcdCopyBackupsTaskCRD,
47+
ResourceNameEtcd: selectedEtcdCRD,
48+
ResourceNameEtcdCopyBackupsTask: etcdCopyBackupsTaskCRD,
4749
}, nil
4850
}
4951

api/core/crds/crd_test.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,48 @@ func TestGetAll(t *testing.T) {
2020
name: "k8s version is 1.29",
2121
k8sVersion: "1.29",
2222
expectedCRDs: map[string]string{
23-
KindEtcd: etcdCRD,
24-
KindEtcdCopyBackupsTask: etcdCopyBackupsTaskCRD,
23+
ResourceNameEtcd: etcdCRD,
24+
ResourceNameEtcdCopyBackupsTask: etcdCopyBackupsTaskCRD,
2525
},
2626
},
2727
{
2828
name: "k8s version is v1.29.0",
2929
k8sVersion: "v1.29.0",
3030
expectedCRDs: map[string]string{
31-
KindEtcd: etcdCRD,
32-
KindEtcdCopyBackupsTask: etcdCopyBackupsTaskCRD,
31+
ResourceNameEtcd: etcdCRD,
32+
ResourceNameEtcdCopyBackupsTask: etcdCopyBackupsTaskCRD,
3333
},
3434
},
3535
{
3636
name: "k8s version is below 1.29",
3737
k8sVersion: "1.28",
3838
expectedCRDs: map[string]string{
39-
KindEtcd: etcdCRDWithoutCEL,
40-
KindEtcdCopyBackupsTask: etcdCopyBackupsTaskCRD,
39+
ResourceNameEtcd: etcdCRDWithoutCEL,
40+
ResourceNameEtcdCopyBackupsTask: etcdCopyBackupsTaskCRD,
4141
},
4242
},
4343
{
4444
name: "k8s version is below v1.29",
4545
k8sVersion: "v1.28.3",
4646
expectedCRDs: map[string]string{
47-
KindEtcd: etcdCRDWithoutCEL,
48-
KindEtcdCopyBackupsTask: etcdCopyBackupsTaskCRD,
47+
ResourceNameEtcd: etcdCRDWithoutCEL,
48+
ResourceNameEtcdCopyBackupsTask: etcdCopyBackupsTaskCRD,
4949
},
5050
},
5151
{
5252
name: "k8s version is above 1.29",
5353
k8sVersion: "1.30",
5454
expectedCRDs: map[string]string{
55-
KindEtcd: etcdCRD,
56-
KindEtcdCopyBackupsTask: etcdCopyBackupsTaskCRD,
55+
ResourceNameEtcd: etcdCRD,
56+
ResourceNameEtcdCopyBackupsTask: etcdCopyBackupsTaskCRD,
5757
},
5858
},
5959
{
6060
name: "k8s version is above v1.29",
6161
k8sVersion: "v1.30.1",
6262
expectedCRDs: map[string]string{
63-
KindEtcd: etcdCRD,
64-
KindEtcdCopyBackupsTask: etcdCopyBackupsTaskCRD,
63+
ResourceNameEtcd: etcdCRD,
64+
ResourceNameEtcdCopyBackupsTask: etcdCopyBackupsTaskCRD,
6565
},
6666
},
6767
}

test/it/assets/assets.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ import (
1515
. "github.com/onsi/gomega"
1616
)
1717

18-
// returns the kubernetes version used from the environment variable
18+
// GetK8sVersionFromEnv returns the kubernetes version used from the environment variable
1919
func GetK8sVersionFromEnv() (string, error) {
2020
k8sVersion, isPresent := os.LookupEnv("ENVTEST_K8S_VERSION")
2121
if isPresent {
2222
return k8sVersion, nil
2323
} else {
24-
return "", errors.New("Error fetching k8s version from environment")
24+
return "", errors.New("error fetching k8s version from environment")
2525
}
2626
}
2727

28-
// Duplicating some code here that can be replaced with a call to the API module of etcd-druid.
28+
// Duplicating some code here that can be replaced with a call to the API module of etcd-druid.
2929
// This will be removed once Kubernetes 1.29 becomes the minimum supported version.
3030

3131
// GetEtcdCrdPath returns the path to the Etcd CRD for k8s versions >= 1.29 or the path to the Etcd CRD without CEL expressions (For versions < 1.29)

test/it/crdvalidation/etcd/helper.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import (
1212
druidv1alpha1 "github.com/gardener/etcd-druid/api/core/v1alpha1"
1313
"github.com/gardener/etcd-druid/test/it/setup"
1414
"github.com/gardener/etcd-druid/test/utils"
15+
1516
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1617
"sigs.k8s.io/controller-runtime/pkg/client"
1718

1819
. "github.com/onsi/gomega"
1920
)
2021

21-
2222
const testNamespacePrefix = "etcd-validation-test"
2323

2424
var (
@@ -46,6 +46,7 @@ func validateEtcdUpdation(t *testing.T, g *WithT, etcd *druidv1alpha1.Etcd, expe
4646
g.Expect(updateErr).To(BeNil())
4747
}
4848
}
49+
4950
var cronFieldTestCases = []struct {
5051
name string
5152
etcdName string
@@ -171,4 +172,4 @@ func setupTestEnvironment(t *testing.T) (string, *WithT) {
171172
g.Expect(itTestEnv.StartManager()).To(Succeed())
172173

173174
return testNs, g
174-
}
175+
}

test/it/crdvalidation/etcd/specetcd_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -123,39 +123,39 @@ func TestValidateSpecStorageCapacitySpecEtcdQuotaRelation(t *testing.T) {
123123
etcdName string
124124
storageCapacity resource.Quantity
125125
quota resource.Quantity
126-
backupEnabled bool
126+
backupEnabled bool
127127
expectErr bool
128128
}{
129129
{
130130
name: "Valid #1: backups enabled",
131131
etcdName: "etcd-valid-1",
132132
storageCapacity: resource.MustParse("27Gi"),
133133
quota: resource.MustParse("8Gi"),
134-
backupEnabled: true,
134+
backupEnabled: true,
135135
expectErr: false,
136136
},
137137
{
138138
name: "Valid #2: backups disabled",
139139
etcdName: "etcd-valid-2",
140140
storageCapacity: resource.MustParse("12Gi"),
141141
quota: resource.MustParse("8Gi"),
142-
backupEnabled: false,
142+
backupEnabled: false,
143143
expectErr: false,
144144
},
145145
{
146146
name: "Invalid #1: backups enabled",
147147
etcdName: "etcd-invalid-1",
148148
storageCapacity: resource.MustParse("15Gi"),
149149
quota: resource.MustParse("8Gi"),
150-
backupEnabled: true,
150+
backupEnabled: true,
151151
expectErr: true,
152152
},
153153
{
154154
name: "Invalid #2: backups disabled",
155155
etcdName: "etcd-invalid-2",
156156
storageCapacity: resource.MustParse("9Gi"),
157157
quota: resource.MustParse("10Gi"),
158-
backupEnabled: false,
158+
backupEnabled: false,
159159
expectErr: true,
160160
},
161161
}

test/it/crdvalidation/etcd/specsharedconfig_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/gardener/etcd-druid/test/utils"
1414
)
1515

16-
1716
// validates whether the value passed to the etcd.spec.sharedConfig.autoCompactionMode is either set as "periodic" or "revision"
1817
func TestValidateSpecSharedConfigAutoCompactionMode(t *testing.T) {
1918
tests := []struct {

0 commit comments

Comments
 (0)