mirror of https://github.com/k3s-io/k3s
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).pull/564/head
parent
cf805f5af4
commit
25c615c157
|
@ -347,7 +347,7 @@ func testCRListConversion(f *framework.Framework, testCrd *crd.TestCrd) {
|
|||
Expect(err).To(BeNil())
|
||||
|
||||
// Now cr-instance-1 is stored as v1. lets change storage version
|
||||
crd, err = integration.UpdateCustomResourceDefinitionWithRetry(testCrd.ApiExtensionClient, crd.Name, func(c *v1beta1.CustomResourceDefinition) {
|
||||
crd, err = integration.UpdateCustomResourceDefinitionWithRetry(testCrd.APIExtensionClient, crd.Name, func(c *v1beta1.CustomResourceDefinition) {
|
||||
c.Spec.Versions = alternativeApiVersions
|
||||
})
|
||||
Expect(err).To(BeNil())
|
||||
|
|
|
@ -59,7 +59,7 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Feature:CustomResourcePublish
|
|||
framework.Failf("%v", err)
|
||||
}
|
||||
|
||||
meta := fmt.Sprintf(metaPattern, crd.Kind, crd.ApiGroup, crd.Versions[0].Name, "test-foo")
|
||||
meta := fmt.Sprintf(metaPattern, crd.Kind, crd.APIGroup, crd.Versions[0].Name, "test-foo")
|
||||
ns := fmt.Sprintf("--namespace=%v", f.Namespace.Name)
|
||||
|
||||
By("client-side validation (kubectl create and apply) allows request with known and required properties")
|
||||
|
@ -127,7 +127,7 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Feature:CustomResourcePublish
|
|||
framework.Failf("%v", err)
|
||||
}
|
||||
|
||||
meta := fmt.Sprintf(metaPattern, crd.Kind, crd.ApiGroup, crd.Versions[0].Name, "test-cr")
|
||||
meta := fmt.Sprintf(metaPattern, crd.Kind, crd.APIGroup, crd.Versions[0].Name, "test-cr")
|
||||
ns := fmt.Sprintf("--namespace=%v", f.Namespace.Name)
|
||||
|
||||
By("client-side validation (kubectl create and apply) allows request with any unknown properties")
|
||||
|
@ -165,8 +165,8 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Feature:CustomResourcePublish
|
|||
if err != nil {
|
||||
framework.Failf("%v", err)
|
||||
}
|
||||
if crdFoo.ApiGroup == crdWaldo.ApiGroup {
|
||||
framework.Failf("unexpected: CRDs should be of different group %v, %v", crdFoo.ApiGroup, crdWaldo.ApiGroup)
|
||||
if crdFoo.APIGroup == crdWaldo.APIGroup {
|
||||
framework.Failf("unexpected: CRDs should be of different group %v, %v", crdFoo.APIGroup, crdWaldo.APIGroup)
|
||||
}
|
||||
if err := waitForDefinition(f.ClientSet, definitionName(crdWaldo, "v1beta1"), schemaWaldo); err != nil {
|
||||
framework.Failf("%v", err)
|
||||
|
@ -207,8 +207,8 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Feature:CustomResourcePublish
|
|||
if err != nil {
|
||||
framework.Failf("%v", err)
|
||||
}
|
||||
if crdFoo.ApiGroup != crdWaldo.ApiGroup {
|
||||
framework.Failf("unexpected: CRDs should be of the same group %v, %v", crdFoo.ApiGroup, crdWaldo.ApiGroup)
|
||||
if crdFoo.APIGroup != crdWaldo.APIGroup {
|
||||
framework.Failf("unexpected: CRDs should be of the same group %v, %v", crdFoo.APIGroup, crdWaldo.APIGroup)
|
||||
}
|
||||
if err := waitForDefinition(f.ClientSet, definitionName(crdWaldo, "v5"), schemaWaldo); err != nil {
|
||||
framework.Failf("%v", err)
|
||||
|
@ -234,8 +234,8 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Feature:CustomResourcePublish
|
|||
if err != nil {
|
||||
framework.Failf("%v", err)
|
||||
}
|
||||
if crdFoo.ApiGroup != crdWaldo.ApiGroup {
|
||||
framework.Failf("unexpected: CRDs should be of the same group %v, %v", crdFoo.ApiGroup, crdWaldo.ApiGroup)
|
||||
if crdFoo.APIGroup != crdWaldo.APIGroup {
|
||||
framework.Failf("unexpected: CRDs should be of the same group %v, %v", crdFoo.APIGroup, crdWaldo.APIGroup)
|
||||
}
|
||||
if err := waitForDefinition(f.ClientSet, definitionName(crdWaldo, "v6"), schemaWaldo); err != nil {
|
||||
framework.Failf("%v", err)
|
||||
|
@ -266,7 +266,7 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Feature:CustomResourcePublish
|
|||
|
||||
By("rename a version")
|
||||
patch := []byte(`{"spec":{"versions":[{"name":"v2","served":true,"storage":true},{"name":"v4","served":true,"storage":false}]}}`)
|
||||
crdMultiVer.Crd, err = crdMultiVer.ApiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Patch(crdMultiVer.GetMetaName(), types.MergePatchType, patch)
|
||||
crdMultiVer.Crd, err = crdMultiVer.APIExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Patch(crdMultiVer.GetMetaName(), types.MergePatchType, patch)
|
||||
if err != nil {
|
||||
framework.Failf("%v", err)
|
||||
}
|
||||
|
@ -308,7 +308,7 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Feature:CustomResourcePublish
|
|||
|
||||
By("mark a version not serverd")
|
||||
crd.Crd.Spec.Versions[1].Served = false
|
||||
crd.Crd, err = crd.ApiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Update(crd.Crd)
|
||||
crd.Crd, err = crd.APIExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Update(crd.Crd)
|
||||
if err != nil {
|
||||
framework.Failf("%v", err)
|
||||
}
|
||||
|
@ -385,7 +385,7 @@ func patchSchema(schema []byte, crd *crd.TestCrd) error {
|
|||
return fmt.Errorf("failed to create json patch: %v", err)
|
||||
}
|
||||
patch := []byte(fmt.Sprintf(`{"spec":{"validation":{"openAPIV3Schema":%s}}}`, string(s)))
|
||||
crd.Crd, err = crd.ApiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Patch(crd.GetMetaName(), types.MergePatchType, patch)
|
||||
crd.Crd, err = crd.APIExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Patch(crd.GetMetaName(), types.MergePatchType, patch)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -486,7 +486,7 @@ func verifyKubectlExplain(name, pattern string) error {
|
|||
|
||||
// definitionName returns the openapi definition name for given CRD in given version
|
||||
func definitionName(crd *crd.TestCrd, version string) string {
|
||||
return openapiutil.ToRESTFriendlyName(fmt.Sprintf("%s/%s/%s", crd.ApiGroup, version, crd.Kind))
|
||||
return openapiutil.ToRESTFriendlyName(fmt.Sprintf("%s/%s/%s", crd.APIGroup, version, crd.Kind))
|
||||
}
|
||||
|
||||
var schemaFoo = []byte(`description: Foo CRD for Testing
|
||||
|
|
|
@ -47,7 +47,7 @@ var _ = SIGDescribe("Discovery", func() {
|
|||
}
|
||||
defer testcrd.CleanUp()
|
||||
spec := testcrd.Crd.Spec
|
||||
resources, err := testcrd.ApiExtensionClient.Discovery().ServerResourcesForGroupVersion(spec.Group + "/" + spec.Versions[0].Name)
|
||||
resources, err := testcrd.APIExtensionClient.Discovery().ServerResourcesForGroupVersion(spec.Group + "/" + spec.Versions[0].Name)
|
||||
if err != nil {
|
||||
framework.Failf("failed to find the discovery doc for %v: %v", resources, err)
|
||||
}
|
||||
|
|
|
@ -1203,7 +1203,7 @@ func registerWebhookForCustomResource(f *framework.Framework, context *certConte
|
|||
Rules: []v1beta1.RuleWithOperations{{
|
||||
Operations: []v1beta1.OperationType{v1beta1.Create, v1beta1.Update},
|
||||
Rule: v1beta1.Rule{
|
||||
APIGroups: []string{testcrd.ApiGroup},
|
||||
APIGroups: []string{testcrd.APIGroup},
|
||||
APIVersions: testcrd.GetAPIVersions(),
|
||||
Resources: []string{testcrd.GetPluralName()},
|
||||
},
|
||||
|
@ -1244,7 +1244,7 @@ func registerMutatingWebhookForCustomResource(f *framework.Framework, context *c
|
|||
Rules: []v1beta1.RuleWithOperations{{
|
||||
Operations: []v1beta1.OperationType{v1beta1.Create, v1beta1.Update},
|
||||
Rule: v1beta1.Rule{
|
||||
APIGroups: []string{testcrd.ApiGroup},
|
||||
APIGroups: []string{testcrd.APIGroup},
|
||||
APIVersions: testcrd.GetAPIVersions(),
|
||||
Resources: []string{testcrd.GetPluralName()},
|
||||
},
|
||||
|
@ -1263,7 +1263,7 @@ func registerMutatingWebhookForCustomResource(f *framework.Framework, context *c
|
|||
Rules: []v1beta1.RuleWithOperations{{
|
||||
Operations: []v1beta1.OperationType{v1beta1.Create},
|
||||
Rule: v1beta1.Rule{
|
||||
APIGroups: []string{testcrd.ApiGroup},
|
||||
APIGroups: []string{testcrd.APIGroup},
|
||||
APIVersions: testcrd.GetAPIVersions(),
|
||||
Resources: []string{testcrd.GetPluralName()},
|
||||
},
|
||||
|
@ -1361,7 +1361,7 @@ func testMultiVersionCustomResourceWebhook(f *framework.Framework, testcrd *crd.
|
|||
|
||||
By("Patching Custom Resource Definition to set v2 as storage")
|
||||
apiVersionWithV2StoragePatch := fmt.Sprint(`{"spec": {"versions": [{"name": "v1", "storage": false, "served": true},{"name": "v2", "storage": true, "served": true}]}}`)
|
||||
_, err = testcrd.ApiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Patch(testcrd.Crd.Name, types.StrategicMergePatchType, []byte(apiVersionWithV2StoragePatch))
|
||||
_, err = testcrd.APIExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Patch(testcrd.Crd.Name, types.StrategicMergePatchType, []byte(apiVersionWithV2StoragePatch))
|
||||
Expect(err).NotTo(HaveOccurred(), "failed to patch custom resource definition %s in namespace: %s", testcrd.Crd.Name, f.Namespace.Name)
|
||||
|
||||
By("Patching the custom resource while v2 is storage version")
|
||||
|
@ -1431,7 +1431,7 @@ func testCRDDenyWebhook(f *framework.Framework) {
|
|||
testcrd := &crd.TestCrd{
|
||||
Name: name,
|
||||
Kind: kind,
|
||||
ApiGroup: group,
|
||||
APIGroup: group,
|
||||
Versions: apiVersions,
|
||||
}
|
||||
|
||||
|
@ -1454,7 +1454,7 @@ func testCRDDenyWebhook(f *framework.Framework) {
|
|||
},
|
||||
},
|
||||
Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{
|
||||
Group: testcrd.ApiGroup,
|
||||
Group: testcrd.APIGroup,
|
||||
Versions: testcrd.Versions,
|
||||
Names: apiextensionsv1beta1.CustomResourceDefinitionNames{
|
||||
Plural: testcrd.GetPluralName(),
|
||||
|
|
|
@ -833,7 +833,7 @@ metadata:
|
|||
ginkgo.By("sleep for 10s to wait for potential crd openapi publishing alpha feature")
|
||||
time.Sleep(10 * time.Second)
|
||||
|
||||
meta := fmt.Sprintf(metaPattern, crd.Kind, crd.ApiGroup, crd.Versions[0].Name, "test-cr")
|
||||
meta := fmt.Sprintf(metaPattern, crd.Kind, crd.APIGroup, crd.Versions[0].Name, "test-cr")
|
||||
randomCR := fmt.Sprintf(`{%s,"a":{"b":[{"c":"d"}]}}`, meta)
|
||||
if err := createApplyCustomResource(randomCR, f.Namespace.Name, "test-cr", crd); err != nil {
|
||||
framework.Failf("%v", err)
|
||||
|
@ -854,7 +854,7 @@ metadata:
|
|||
ginkgo.By("sleep for 10s to wait for potential crd openapi publishing alpha feature")
|
||||
time.Sleep(10 * time.Second)
|
||||
|
||||
meta := fmt.Sprintf(metaPattern, crd.Kind, crd.ApiGroup, crd.Versions[0].Name, "test-cr")
|
||||
meta := fmt.Sprintf(metaPattern, crd.Kind, crd.APIGroup, crd.Versions[0].Name, "test-cr")
|
||||
validCR := fmt.Sprintf(`{%s,"spec":{"bars":[{"name":"test-bar"}]}}`, meta)
|
||||
if err := createApplyCustomResource(validCR, f.Namespace.Name, "test-cr", crd); err != nil {
|
||||
framework.Failf("%v", err)
|
||||
|
@ -875,7 +875,7 @@ metadata:
|
|||
ginkgo.By("sleep for 10s to wait for potential crd openapi publishing alpha feature")
|
||||
time.Sleep(10 * time.Second)
|
||||
|
||||
meta := fmt.Sprintf(metaPattern, crd.Kind, crd.ApiGroup, crd.Versions[0].Name, "test-cr")
|
||||
meta := fmt.Sprintf(metaPattern, crd.Kind, crd.APIGroup, crd.Versions[0].Name, "test-cr")
|
||||
validArbitraryCR := fmt.Sprintf(`{%s,"spec":{"bars":[{"name":"test-bar"}],"extraProperty":"arbitrary-value"}}`, meta)
|
||||
if err := createApplyCustomResource(validArbitraryCR, f.Namespace.Name, "test-cr", crd); err != nil {
|
||||
framework.Failf("%v", err)
|
||||
|
|
|
@ -37,15 +37,15 @@ type CleanCrdFn func() error
|
|||
type TestCrd struct {
|
||||
Name string
|
||||
Kind string
|
||||
ApiGroup string
|
||||
APIGroup string
|
||||
Versions []apiextensionsv1beta1.CustomResourceDefinitionVersion
|
||||
ApiExtensionClient *crdclientset.Clientset
|
||||
APIExtensionClient *crdclientset.Clientset
|
||||
Crd *apiextensionsv1beta1.CustomResourceDefinition
|
||||
DynamicClients map[string]dynamic.ResourceInterface
|
||||
CleanUp CleanCrdFn
|
||||
}
|
||||
|
||||
// CreateTestCRD creates a new CRD specifically for the calling test.
|
||||
// CreateMultiVersionTestCRD creates a new CRD specifically for the calling test.
|
||||
func CreateMultiVersionTestCRD(f *framework.Framework, group string, apiVersions []apiextensionsv1beta1.CustomResourceDefinitionVersion, conversionWebhook *apiextensionsv1beta1.WebhookClientConfig) (*TestCrd, error) {
|
||||
suffix := framework.RandomSuffix()
|
||||
name := fmt.Sprintf("e2e-test-%s-%s-crd", f.BaseName, suffix)
|
||||
|
@ -53,7 +53,7 @@ func CreateMultiVersionTestCRD(f *framework.Framework, group string, apiVersions
|
|||
testcrd := &TestCrd{
|
||||
Name: name,
|
||||
Kind: kind,
|
||||
ApiGroup: group,
|
||||
APIGroup: group,
|
||||
Versions: apiVersions,
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ func CreateMultiVersionTestCRD(f *framework.Framework, group string, apiVersions
|
|||
}
|
||||
}
|
||||
|
||||
testcrd.ApiExtensionClient = apiExtensionClient
|
||||
testcrd.APIExtensionClient = apiExtensionClient
|
||||
testcrd.Crd = crd
|
||||
testcrd.DynamicClients = resourceClients
|
||||
testcrd.CleanUp = func() error {
|
||||
|
@ -124,7 +124,7 @@ func CreateTestCRD(f *framework.Framework) (*TestCrd, error) {
|
|||
return CreateMultiVersionTestCRD(f, group, apiVersions, nil)
|
||||
}
|
||||
|
||||
// CreateTestCRD creates a new CRD specifically for the calling test.
|
||||
// CreateMultiVersionTestCRDWithV1Storage creates a new CRD specifically for the calling test.
|
||||
func CreateMultiVersionTestCRDWithV1Storage(f *framework.Framework) (*TestCrd, error) {
|
||||
group := fmt.Sprintf("%s-multiversion-crd-test.k8s.io", f.BaseName)
|
||||
apiVersions := []apiextensionsv1beta1.CustomResourceDefinitionVersion{
|
||||
|
@ -147,7 +147,7 @@ func newCRDForTest(testcrd *TestCrd) *apiextensionsv1beta1.CustomResourceDefinit
|
|||
return &apiextensionsv1beta1.CustomResourceDefinition{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: testcrd.GetMetaName()},
|
||||
Spec: apiextensionsv1beta1.CustomResourceDefinitionSpec{
|
||||
Group: testcrd.ApiGroup,
|
||||
Group: testcrd.APIGroup,
|
||||
Versions: testcrd.Versions,
|
||||
Names: apiextensionsv1beta1.CustomResourceDefinitionNames{
|
||||
Plural: testcrd.GetPluralName(),
|
||||
|
@ -162,7 +162,7 @@ func newCRDForTest(testcrd *TestCrd) *apiextensionsv1beta1.CustomResourceDefinit
|
|||
|
||||
// GetMetaName returns the metaname for the CRD.
|
||||
func (c *TestCrd) GetMetaName() string {
|
||||
return c.Name + "s." + c.ApiGroup
|
||||
return c.Name + "s." + c.APIGroup
|
||||
}
|
||||
|
||||
// GetPluralName returns the plural form of the CRD name
|
||||
|
@ -175,6 +175,7 @@ func (c *TestCrd) GetListName() string {
|
|||
return c.Name + "List"
|
||||
}
|
||||
|
||||
// GetAPIVersions returns the API versions served by the CRD.
|
||||
func (c *TestCrd) GetAPIVersions() []string {
|
||||
ret := []string{}
|
||||
for _, v := range c.Versions {
|
||||
|
@ -185,6 +186,7 @@ func (c *TestCrd) GetAPIVersions() []string {
|
|||
return ret
|
||||
}
|
||||
|
||||
// GetV1DynamicClient returns the dynamic client for v1.
|
||||
func (c *TestCrd) GetV1DynamicClient() dynamic.ResourceInterface {
|
||||
return c.DynamicClients["v1"]
|
||||
}
|
||||
|
@ -196,6 +198,6 @@ func (c *TestCrd) PatchSchema(schema []byte) error {
|
|||
return fmt.Errorf("failed to create json patch: %v", err)
|
||||
}
|
||||
patch := []byte(fmt.Sprintf(`{"spec":{"validation":{"openAPIV3Schema":%s}}}`, string(s)))
|
||||
c.Crd, err = c.ApiExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Patch(c.GetMetaName(), types.MergePatchType, patch)
|
||||
c.Crd, err = c.APIExtensionClient.ApiextensionsV1beta1().CustomResourceDefinitions().Patch(c.GetMetaName(), types.MergePatchType, patch)
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue