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 resource rules to krm-kcl spec #54

Merged
merged 3 commits into from
May 2, 2024

Conversation

shruti2522
Copy link
Contributor

1. Does this PR affect any open issues?(Y/N) and add issue references (e.g. "fix #123", "re #123".):

  • N
  • Y

fix #13

2. What is the scope of this PR (e.g. component or file name):

kcl-lang/krm-kcl/pkg/options/testdata/resource_list

3. Provide a description of the PR(e.g. more details, effects, motivations or doc link):

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Other

Added resource matching rules to the krm-kcl spec

4. Are there any breaking changes?(Y/N) and describe the breaking changes(e.g. more details, motivations or doc link):

  • N
  • Y

5. Are there test cases for these changes?(Y/N) select and add more details, references or doc links:

  • Unit test
  • Integration test
  • Benchmark (add benchmark stats below)
  • Manual test (add detailed scripts or steps below)
  • Other

@shruti2522
Copy link
Contributor Author

Please take a look, @Peefy

@Peefy
Copy link
Contributor

Peefy commented Apr 30, 2024

I think we should first implement this feature in the corresponding code before modifying the test cases.

@shruti2522
Copy link
Contributor Author

I have added the MatchConstraints struct and the function to verify resource matching rules to config.go @Peefy

Copy link
Contributor

@Peefy Peefy left a comment

Choose a reason for hiding this comment

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

Good Job! LGTM

@Peefy
Copy link
Contributor

Peefy commented May 1, 2024

Could you please fix the CI?

@shruti2522
Copy link
Contributor Author

I have modified the test cases in config_test.go to address the errors, and make test works fine now.

PASS
ok      kcl-lang.io/krm-kcl     7.814s
shruti@fedora:~/cncf/krm-kcl$

pkg/config/config_test.go Outdated Show resolved Hide resolved
@shruti2522
Copy link
Contributor Author

I think we should use the resourceRules field directly, and remove matchConstraints to resolve the following errors while testing.

FAIL: TestRunLocalPath (0.00s)
    --- FAIL: TestRunLocalPath/resource_list (0.00s)
        run_test.go:72: TestRunLocalPath() error = yaml: unmarshal errors:
              line 10: cannot unmarshal !!map into []config.ResourceRule, wantErr false

Is this the correct approach @Peefy.

@Peefy
Copy link
Contributor

Peefy commented May 1, 2024

I suggest keeping this field as it is consistent with Kubernetes CEL, please refer to https://kubernetes.io/docs/reference/access-authn-authz/validating-admission-policy/#creating -A-validatingadmissionpolicy

@shruti2522
Copy link
Contributor Author

shruti2522 commented May 1, 2024

Any ideas on what might be causing this error @Peefy, since I have tried out correcting any possible syntax or test case error.

pkg/config/config_test.go Outdated Show resolved Hide resolved
pkg/config/config.go Show resolved Hide resolved
pkg/config/config.go Show resolved Hide resolved
Signed-off-by: shruti2522 <shruti.apc01@gmail.com>

add resource matching rules to config.go

Signed-off-by: shruti2522 <shruti.apc01@gmail.com>

fix build and test errors

Signed-off-by: shruti2522 <shruti.apc01@gmail.com>

add test case for missing resource rules

Signed-off-by: shruti2522 <shruti.apc01@gmail.com>

updated yaml test files

Signed-off-by: shruti2522 <shruti.apc01@gmail.com>

test case set to optional

Signed-off-by: shruti2522 <shruti.apc01@gmail.com>

corrected syntax error in yaml

Signed-off-by: shruti2522 <shruti.apc01@gmail.com>

fixed yaml formatting in config_test.go

Signed-off-by: shruti2522 <shruti.apc01@gmail.com>

fixed yaml formatting

Signed-off-by: shruti2522 <shruti.apc01@gmail.com>

updated logic handling for MatchResourceRules

Signed-off-by: shruti2522 <shruti.apc01@gmail.com>

feat: add resource rules to krm-kcl spec

Signed-off-by: shruti2522 <shruti.apc01@gmail.com>
@shruti2522
Copy link
Contributor Author

shruti2522 commented May 2, 2024

Done with the changes @Peefy

pkg/config/config.go Outdated Show resolved Hide resolved
Signed-off-by: shruti2522 <shruti.apc01@gmail.com>
pkg/config/config.go Outdated Show resolved Hide resolved
Signed-off-by: shruti2522 <shruti.apc01@gmail.com>
@Peefy Peefy merged commit 92fd9ba into kcl-lang:main May 2, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement] Consider adding resource matching rules to the KRM-KCL Spec
2 participants