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: add kubebuilders validations for name length to be <= 63 #218

Open
wants to merge 53 commits into
base: main
Choose a base branch
from

Conversation

jamyct
Copy link

@jamyct jamyct commented Nov 15, 2024

What type of PR is this?

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes #

Requirements:

How has this code been tested

Special notes for your reviewer

@jamyct jamyct changed the title add kubebuilders validations for name length to be <= 63 feat: add kubebuilders validations for name length to be <= 63 Nov 15, 2024
Copy link

codecov bot commented Nov 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.26%. Comparing base (7a16d0c) to head (c0acd83).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #218      +/-   ##
==========================================
+ Coverage   80.10%   80.26%   +0.15%     
==========================================
  Files          27       27              
  Lines        3840     3840              
==========================================
+ Hits         3076     3082       +6     
+ Misses        610      603       -7     
- Partials      154      155       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jamyct jamyct added the enhancement New feature or request label Nov 20, 2024
@jamyct jamyct force-pushed the add-resource-validation branch from a87267d to c730655 Compare November 20, 2024 02:13
config/rbac/role.yaml Outdated Show resolved Hide resolved
test/apis/v1alpha1/api_validation_integration_test.go Outdated Show resolved Hide resolved
test/apis/v1alpha1/api_validation_integration_test.go Outdated Show resolved Hide resolved
test/apis/v1alpha1/api_validation_integration_test.go Outdated Show resolved Hide resolved
@zhiying-lin zhiying-lin marked this pull request as draft December 6, 2024 06:10
Makefile Show resolved Hide resolved
@jamyct jamyct marked this pull request as ready for review December 12, 2024 02:55
Makefile Outdated Show resolved Hide resolved
test/apis/v1alpha1/suite_test.go Outdated Show resolved Hide resolved
test/apis/v1alpha1/suite_test.go Show resolved Hide resolved
test/apis/v1alpha1/suite_test.go Outdated Show resolved Hide resolved
test/apis/v1alpha1/api_validation_integration_test.go Outdated Show resolved Hide resolved
test/apis/v1alpha1/api_validation_integration_test.go Outdated Show resolved Hide resolved
test/apis/v1alpha1/api_validation_integration_test.go Outdated Show resolved Hide resolved
test/apis/v1alpha1/api_validation_integration_test.go Outdated Show resolved Hide resolved
test/apis/v1alpha1/api_validation_integration_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@zhiying-lin zhiying-lin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please apply the comments to all the APIs tests.

@@ -110,8 +110,9 @@ local-unit-test: $(ENVTEST) ## Run tests.

.PHONY: integration-test
integration-test: $(ENVTEST) ## Run integration tests.
go install github.com/onsi/ginkgo/v2/[email protected]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please install the ginko in the .github/workflows/unit-integration-tests.yml similar to what fleet repo does.
https://github.com/Azure/fleet/blob/main/.github/workflows/ci.yml#L47

Expect(errors.As(err, &statusErr)).To(BeTrue(), fmt.Sprintf("Create API call produced error %s. Error type wanted is %s.", reflect.TypeOf(err), reflect.TypeOf(&k8serrors.StatusError{})))
Expect(statusErr.Status().Message).Should(ContainSubstring("metadata.name max length is 63"))
})

It("should deny creating API with invalid name starting with non-alphanumeric character", func() {
var name = "-abcdef-123456789-123456789-123456789-123456789-123456789"
var nameStartingWithNonAlphanum = "-abcdef-123456789-123456789-123456789-123456789-123456789"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make it as a global variable, so that it can be shared between all the resources.

ctx context.Context
cancel context.CancelFunc
testNamespace = "testnamespace"
nameWithInvalidSize = "abcdef-123456789-123456789-123456789-123456789-123456789-123456789-123456789"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please declare this varible in api_validation_integration_test.go file where you used it.

Name: testNamespace,
},
}
Expect(hubClient.Delete(ctx, &ns)).Should(Succeed())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Expect(hubClient.Delete(ctx, &ns)).Should(Succeed())
Expect(hubClient.Delete(ctx, &ns)).Should(Succeed(), failed to delete namespace)

},
}
Expect(hubClient.Create(ctx, &ns)).Should(Succeed())
Expect(hubClient.Create(ctx, &ns)).Should(Succeed(), "failed to delete namespace")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Expect(hubClient.Create(ctx, &ns)).Should(Succeed(), "failed to delete namespace")
Expect(hubClient.Create(ctx, &ns)).Should(Succeed(), "failed to create namespace")

@@ -133,13 +131,13 @@ var _ = Describe("Test networking v1alpha1 API validation", func() {
})

It("should allow creating API with valid name starting with alphabet character", func() {
var name = "abc-123456789"
var nameValid = "abc-123456789"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please create the global variable nameValidStartingWithAphabet = "abc-123456789", so that we can distinguish them and reuse for all the resources.

},
},
}
Expect(hubClient.Create(ctx, multiClusterServiceName)).Should(Succeed())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Expect(hubClient.Create(ctx, multiClusterServiceName)).Should(Succeed())
Expect(hubClient.Create(ctx, multiClusterServiceName)).Should(Succeed(), "failed to create multiClusterService")

missed this before, feel better to add the debug information here

},
}
Expect(hubClient.Create(ctx, multiClusterServiceName)).Should(Succeed())
Expect(hubClient.Delete(ctx, multiClusterServiceName)).Should(Succeed())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Expect(hubClient.Delete(ctx, multiClusterServiceName)).Should(Succeed())
Expect(hubClient.Delete(ctx, multiClusterServiceName)).Should(Succeed(), "failed to delete multiClusterService")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants