Skip to content

Commit 25c615c

Browse files
committed
test: fix golint warnings in crd_util.go
Because the code was moved, golint is now active. Because users of the code must adapt to the new location of the code, it makes sense to also change the API at the same time to address the style comments from golint ("struct field ApiGroup should be APIGroup", same for ApiExtensionClient).
1 parent cf805f5 commit 25c615c

File tree

6 files changed

+34
-32
lines changed

6 files changed

+34
-32
lines changed

test/e2e/apimachinery/crd_conversion_webhook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ func testCRListConversion(f *framework.Framework, testCrd *crd.TestCrd) {
347347
Expect(err).To(BeNil())
348348

349349
// Now cr-instance-1 is stored as v1. lets change storage version
350-
crd, err = integration.UpdateCustomResourceDefinitionWithRetry(testCrd.ApiExtensionClient, crd.Name, func(c *v1beta1.CustomResourceDefinition) {
350+
crd, err = integration.UpdateCustomResourceDefinitionWithRetry(testCrd.APIExtensionClient, crd.Name, func(c *v1beta1.CustomResourceDefinition) {
351351
c.Spec.Versions = alternativeApiVersions
352352
})
353353
Expect(err).To(BeNil())

test/e2e/apimachinery/crd_publish_openapi.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Feature:CustomResourcePublish
5959
framework.Failf("%v", err)
6060
}
6161

62-
meta := fmt.Sprintf(metaPattern, crd.Kind, crd.ApiGroup, crd.Versions[0].Name, "test-foo")
62+
meta := fmt.Sprintf(metaPattern, crd.Kind, crd.APIGroup, crd.Versions[0].Name, "test-foo")
6363
ns := fmt.Sprintf("--namespace=%v", f.Namespace.Name)
6464

6565
By("client-side validation (kubectl create and apply) allows request with known and required properties")
@@ -127,7 +127,7 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Feature:CustomResourcePublish
127127
framework.Failf("%v", err)
128128
}
129129

130-
meta := fmt.Sprintf(metaPattern, crd.Kind, crd.ApiGroup, crd.Versions[0].Name, "test-cr")
130+
meta := fmt.Sprintf(metaPattern, crd.Kind, crd.APIGroup, crd.Versions[0].Name, "test-cr")
131131
ns := fmt.Sprintf("--namespace=%v", f.Namespace.Name)
132132

133133
By("client-side validation (kubectl create and apply) allows request with any unknown properties")
@@ -165,8 +165,8 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Feature:CustomResourcePublish
165165
if err != nil {
166166
framework.Failf("%v", err)
167167
}
168-
if crdFoo.ApiGroup == crdWaldo.ApiGroup {
169-
framework.Failf("unexpected: CRDs should be of different group %v, %v", crdFoo.ApiGroup, crdWaldo.ApiGroup)
168+
if crdFoo.APIGroup == crdWaldo.APIGroup {
169+
framework.Failf("unexpected: CRDs should be of different group %v, %v", crdFoo.APIGroup, crdWaldo.APIGroup)
170170
}
171171
if err := waitForDefinition(f.ClientSet, definitionName(crdWaldo, "v1beta1"), schemaWaldo); err != nil {
172172
framework.Failf("%v", err)
@@ -207,8 +207,8 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Feature:CustomResourcePublish
207207
if err != nil {
208208
framework.Failf("%v", err)
209209
}
210-
if crdFoo.ApiGroup != crdWaldo.ApiGroup {
211-
framework.Failf("unexpected: CRDs should be of the same group %v, %v", crdFoo.ApiGroup, crdWaldo.ApiGroup)
210+
if crdFoo.APIGroup != crdWaldo.APIGroup {
211+
framework.Failf("unexpected: CRDs should be of the same group %v, %v", crdFoo.APIGroup, crdWaldo.APIGroup)
212212
}
213213
if err := waitForDefinition(f.ClientSet, definitionName(crdWaldo, "v5"), schemaWaldo); err != nil {
214214
framework.Failf("%v", err)
@@ -234,8 +234,8 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Feature:CustomResourcePublish
234234
if err != nil {
235235
framework.Failf("%v", err)
236236
}
237-
if crdFoo.ApiGroup != crdWaldo.ApiGroup {
238-
framework.Failf("unexpected: CRDs should be of the same group %v, %v", crdFoo.ApiGroup, crdWaldo.ApiGroup)
237+
if crdFoo.APIGroup != crdWaldo.APIGroup {
238+
framework.Failf("unexpected: CRDs should be of the same group %v, %v", crdFoo.APIGroup, crdWaldo.APIGroup)
239239
}
240240
if err := waitForDefinition(f.ClientSet, definitionName(crdWaldo, "v6"), schemaWaldo); err != nil {
241241
framework.Failf("%v", err)
@@ -266,7 +266,7 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Feature:CustomResourcePublish
266266

267267
By("rename a version")
268268
patch := []byte(`{"spec":{"versions":[{"name":"v2","served":true,"storage":true},{"name":"v4","served":true,"storage":false}]}}`)
269-
crdMultiVer.Crd, err = crdMultiVer.ApiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Patch(crdMultiVer.GetMetaName(), types.MergePatchType, patch)
269+
crdMultiVer.Crd, err = crdMultiVer.APIExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Patch(crdMultiVer.GetMetaName(), types.MergePatchType, patch)
270270
if err != nil {
271271
framework.Failf("%v", err)
272272
}
@@ -308,7 +308,7 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Feature:CustomResourcePublish
308308

309309
By("mark a version not serverd")
310310
crd.Crd.Spec.Versions[1].Served = false
311-
crd.Crd, err = crd.ApiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Update(crd.Crd)
311+
crd.Crd, err = crd.APIExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Update(crd.Crd)
312312
if err != nil {
313313
framework.Failf("%v", err)
314314
}
@@ -385,7 +385,7 @@ func patchSchema(schema []byte, crd *crd.TestCrd) error {
385385
return fmt.Errorf("failed to create json patch: %v", err)
386386
}
387387
patch := []byte(fmt.Sprintf(`{"spec":{"validation":{"openAPIV3Schema":%s}}}`, string(s)))
388-
crd.Crd, err = crd.ApiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Patch(crd.GetMetaName(), types.MergePatchType, patch)
388+
crd.Crd, err = crd.APIExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Patch(crd.GetMetaName(), types.MergePatchType, patch)
389389
return err
390390
}
391391

@@ -486,7 +486,7 @@ func verifyKubectlExplain(name, pattern string) error {
486486

487487
// definitionName returns the openapi definition name for given CRD in given version
488488
func definitionName(crd *crd.TestCrd, version string) string {
489-
return openapiutil.ToRESTFriendlyName(fmt.Sprintf("%s/%s/%s", crd.ApiGroup, version, crd.Kind))
489+
return openapiutil.ToRESTFriendlyName(fmt.Sprintf("%s/%s/%s", crd.APIGroup, version, crd.Kind))
490490
}
491491

492492
var schemaFoo = []byte(`description: Foo CRD for Testing

test/e2e/apimachinery/discovery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var _ = SIGDescribe("Discovery", func() {
4747
}
4848
defer testcrd.CleanUp()
4949
spec := testcrd.Crd.Spec
50-
resources, err := testcrd.ApiExtensionClient.Discovery().ServerResourcesForGroupVersion(spec.Group + "/" + spec.Versions[0].Name)
50+
resources, err := testcrd.APIExtensionClient.Discovery().ServerResourcesForGroupVersion(spec.Group + "/" + spec.Versions[0].Name)
5151
if err != nil {
5252
framework.Failf("failed to find the discovery doc for %v: %v", resources, err)
5353
}

test/e2e/apimachinery/webhook.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ func registerWebhookForCustomResource(f *framework.Framework, context *certConte
12031203
Rules: []v1beta1.RuleWithOperations{{
12041204
Operations: []v1beta1.OperationType{v1beta1.Create, v1beta1.Update},
12051205
Rule: v1beta1.Rule{
1206-
APIGroups: []string{testcrd.ApiGroup},
1206+
APIGroups: []string{testcrd.APIGroup},
12071207
APIVersions: testcrd.GetAPIVersions(),
12081208
Resources: []string{testcrd.GetPluralName()},
12091209
},
@@ -1244,7 +1244,7 @@ func registerMutatingWebhookForCustomResource(f *framework.Framework, context *c
12441244
Rules: []v1beta1.RuleWithOperations{{
12451245
Operations: []v1beta1.OperationType{v1beta1.Create, v1beta1.Update},
12461246
Rule: v1beta1.Rule{
1247-
APIGroups: []string{testcrd.ApiGroup},
1247+
APIGroups: []string{testcrd.APIGroup},
12481248
APIVersions: testcrd.GetAPIVersions(),
12491249
Resources: []string{testcrd.GetPluralName()},
12501250
},
@@ -1263,7 +1263,7 @@ func registerMutatingWebhookForCustomResource(f *framework.Framework, context *c
12631263
Rules: []v1beta1.RuleWithOperations{{
12641264
Operations: []v1beta1.OperationType{v1beta1.Create},
12651265
Rule: v1beta1.Rule{
1266-
APIGroups: []string{testcrd.ApiGroup},
1266+
APIGroups: []string{testcrd.APIGroup},
12671267
APIVersions: testcrd.GetAPIVersions(),
12681268
Resources: []string{testcrd.GetPluralName()},
12691269
},
@@ -1361,7 +1361,7 @@ func testMultiVersionCustomResourceWebhook(f *framework.Framework, testcrd *crd.
13611361

13621362
By("Patching Custom Resource Definition to set v2 as storage")
13631363
apiVersionWithV2StoragePatch := fmt.Sprint(`{"spec": {"versions": [{"name": "v1", "storage": false, "served": true},{"name": "v2", "storage": true, "served": true}]}}`)
1364-
_, err = testcrd.ApiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Patch(testcrd.Crd.Name, types.StrategicMergePatchType, []byte(apiVersionWithV2StoragePatch))
1364+
_, err = testcrd.APIExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Patch(testcrd.Crd.Name, types.StrategicMergePatchType, []byte(apiVersionWithV2StoragePatch))
13651365
Expect(err).NotTo(HaveOccurred(), "failed to patch custom resource definition %s in namespace: %s", testcrd.Crd.Name, f.Namespace.Name)
13661366

13671367
By("Patching the custom resource while v2 is storage version")
@@ -1431,7 +1431,7 @@ func testCRDDenyWebhook(f *framework.Framework) {
14311431
testcrd := &crd.TestCrd{
14321432
Name: name,
14331433
Kind: kind,
1434-
ApiGroup: group,
1434+
APIGroup: group,
14351435
Versions: apiVersions,
14361436
}
14371437

@@ -1454,7 +1454,7 @@ func testCRDDenyWebhook(f *framework.Framework) {
14541454
},
14551455
},
14561456
Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{
1457-
Group: testcrd.ApiGroup,
1457+
Group: testcrd.APIGroup,
14581458
Versions: testcrd.Versions,
14591459
Names: apiextensionsv1beta1.CustomResourceDefinitionNames{
14601460
Plural: testcrd.GetPluralName(),

test/e2e/kubectl/kubectl.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ metadata:
833833
ginkgo.By("sleep for 10s to wait for potential crd openapi publishing alpha feature")
834834
time.Sleep(10 * time.Second)
835835

836-
meta := fmt.Sprintf(metaPattern, crd.Kind, crd.ApiGroup, crd.Versions[0].Name, "test-cr")
836+
meta := fmt.Sprintf(metaPattern, crd.Kind, crd.APIGroup, crd.Versions[0].Name, "test-cr")
837837
randomCR := fmt.Sprintf(`{%s,"a":{"b":[{"c":"d"}]}}`, meta)
838838
if err := createApplyCustomResource(randomCR, f.Namespace.Name, "test-cr", crd); err != nil {
839839
framework.Failf("%v", err)
@@ -854,7 +854,7 @@ metadata:
854854
ginkgo.By("sleep for 10s to wait for potential crd openapi publishing alpha feature")
855855
time.Sleep(10 * time.Second)
856856

857-
meta := fmt.Sprintf(metaPattern, crd.Kind, crd.ApiGroup, crd.Versions[0].Name, "test-cr")
857+
meta := fmt.Sprintf(metaPattern, crd.Kind, crd.APIGroup, crd.Versions[0].Name, "test-cr")
858858
validCR := fmt.Sprintf(`{%s,"spec":{"bars":[{"name":"test-bar"}]}}`, meta)
859859
if err := createApplyCustomResource(validCR, f.Namespace.Name, "test-cr", crd); err != nil {
860860
framework.Failf("%v", err)
@@ -875,7 +875,7 @@ metadata:
875875
ginkgo.By("sleep for 10s to wait for potential crd openapi publishing alpha feature")
876876
time.Sleep(10 * time.Second)
877877

878-
meta := fmt.Sprintf(metaPattern, crd.Kind, crd.ApiGroup, crd.Versions[0].Name, "test-cr")
878+
meta := fmt.Sprintf(metaPattern, crd.Kind, crd.APIGroup, crd.Versions[0].Name, "test-cr")
879879
validArbitraryCR := fmt.Sprintf(`{%s,"spec":{"bars":[{"name":"test-bar"}],"extraProperty":"arbitrary-value"}}`, meta)
880880
if err := createApplyCustomResource(validArbitraryCR, f.Namespace.Name, "test-cr", crd); err != nil {
881881
framework.Failf("%v", err)

test/utils/crd/crd_util.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,23 @@ type CleanCrdFn func() error
3737
type TestCrd struct {
3838
Name string
3939
Kind string
40-
ApiGroup string
40+
APIGroup string
4141
Versions []apiextensionsv1beta1.CustomResourceDefinitionVersion
42-
ApiExtensionClient *crdclientset.Clientset
42+
APIExtensionClient *crdclientset.Clientset
4343
Crd *apiextensionsv1beta1.CustomResourceDefinition
4444
DynamicClients map[string]dynamic.ResourceInterface
4545
CleanUp CleanCrdFn
4646
}
4747

48-
// CreateTestCRD creates a new CRD specifically for the calling test.
48+
// CreateMultiVersionTestCRD creates a new CRD specifically for the calling test.
4949
func CreateMultiVersionTestCRD(f *framework.Framework, group string, apiVersions []apiextensionsv1beta1.CustomResourceDefinitionVersion, conversionWebhook *apiextensionsv1beta1.WebhookClientConfig) (*TestCrd, error) {
5050
suffix := framework.RandomSuffix()
5151
name := fmt.Sprintf("e2e-test-%s-%s-crd", f.BaseName, suffix)
5252
kind := fmt.Sprintf("E2e-test-%s-%s-crd", f.BaseName, suffix)
5353
testcrd := &TestCrd{
5454
Name: name,
5555
Kind: kind,
56-
ApiGroup: group,
56+
APIGroup: group,
5757
Versions: apiVersions,
5858
}
5959

@@ -98,7 +98,7 @@ func CreateMultiVersionTestCRD(f *framework.Framework, group string, apiVersions
9898
}
9999
}
100100

101-
testcrd.ApiExtensionClient = apiExtensionClient
101+
testcrd.APIExtensionClient = apiExtensionClient
102102
testcrd.Crd = crd
103103
testcrd.DynamicClients = resourceClients
104104
testcrd.CleanUp = func() error {
@@ -124,7 +124,7 @@ func CreateTestCRD(f *framework.Framework) (*TestCrd, error) {
124124
return CreateMultiVersionTestCRD(f, group, apiVersions, nil)
125125
}
126126

127-
// CreateTestCRD creates a new CRD specifically for the calling test.
127+
// CreateMultiVersionTestCRDWithV1Storage creates a new CRD specifically for the calling test.
128128
func CreateMultiVersionTestCRDWithV1Storage(f *framework.Framework) (*TestCrd, error) {
129129
group := fmt.Sprintf("%s-multiversion-crd-test.k8s.io", f.BaseName)
130130
apiVersions := []apiextensionsv1beta1.CustomResourceDefinitionVersion{
@@ -147,7 +147,7 @@ func newCRDForTest(testcrd *TestCrd) *apiextensionsv1beta1.CustomResourceDefinit
147147
return &apiextensionsv1beta1.CustomResourceDefinition{
148148
ObjectMeta: metav1.ObjectMeta{Name: testcrd.GetMetaName()},
149149
Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{
150-
Group: testcrd.ApiGroup,
150+
Group: testcrd.APIGroup,
151151
Versions: testcrd.Versions,
152152
Names: apiextensionsv1beta1.CustomResourceDefinitionNames{
153153
Plural: testcrd.GetPluralName(),
@@ -162,7 +162,7 @@ func newCRDForTest(testcrd *TestCrd) *apiextensionsv1beta1.CustomResourceDefinit
162162

163163
// GetMetaName returns the metaname for the CRD.
164164
func (c *TestCrd) GetMetaName() string {
165-
return c.Name + "s." + c.ApiGroup
165+
return c.Name + "s." + c.APIGroup
166166
}
167167

168168
// GetPluralName returns the plural form of the CRD name
@@ -175,6 +175,7 @@ func (c *TestCrd) GetListName() string {
175175
return c.Name + "List"
176176
}
177177

178+
// GetAPIVersions returns the API versions served by the CRD.
178179
func (c *TestCrd) GetAPIVersions() []string {
179180
ret := []string{}
180181
for _, v := range c.Versions {
@@ -185,6 +186,7 @@ func (c *TestCrd) GetAPIVersions() []string {
185186
return ret
186187
}
187188

189+
// GetV1DynamicClient returns the dynamic client for v1.
188190
func (c *TestCrd) GetV1DynamicClient() dynamic.ResourceInterface {
189191
return c.DynamicClients["v1"]
190192
}
@@ -196,6 +198,6 @@ func (c *TestCrd) PatchSchema(schema []byte) error {
196198
return fmt.Errorf("failed to create json patch: %v", err)
197199
}
198200
patch := []byte(fmt.Sprintf(`{"spec":{"validation":{"openAPIV3Schema":%s}}}`, string(s)))
199-
c.Crd, err = c.ApiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Patch(c.GetMetaName(), types.MergePatchType, patch)
201+
c.Crd, err = c.APIExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Patch(c.GetMetaName(), types.MergePatchType, patch)
200202
return err
201203
}

0 commit comments

Comments
 (0)