-
Notifications
You must be signed in to change notification settings - Fork 42
KUBE-997: add policies per feature #469
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
Merged
Merged
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
1444332
KUBE-997: add policy per feature
ValyaB 74cfd5e
KUBE-997: lint
ValyaB 7f646db
KUBE-997: gen sdk
ValyaB a134f9e
KUBE-997: refactor
ValyaB 8eaf62c
KUBE-997: refactor
ValyaB 4bff5bf
KUBE-997: refactor
ValyaB a30a2b5
KUBE-997: rename
ValyaB 2967234
KUBE-997: rename
ValyaB 833e8e4
KUBE-997: docs
ValyaB bbc736c
KUBE-997: set as optional
ValyaB 6610752
Merge branch 'master' into nojira-add-policy-per-feature
ValyaB 06af68b
KUBE-997: fix error
ValyaB c78c983
KUBE-997: tests
ValyaB b5a05eb
KUBE-997: tests
ValyaB eeae501
Update castai/data_source_gke.go
ValyaB 3d00279
KUBE-997: rename
ValyaB 750459d
Update castai/data_source_gke.go
ValyaB b69cd86
KUBE-997: lint
ValyaB 7c4930a
KUBE-997: clean
ValyaB d3fe826
KUBE-997: clean
ValyaB 96f80a1
KUBE-997: refactor
ValyaB 22ae879
KUBE-997: test
ValyaB 6a68d06
KUBE-997: test
ValyaB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| package castai | ||
|
|
||
| import ( | ||
| "context" | ||
| "github.com/castai/terraform-provider-castai/castai/policies/gke" | ||
| "github.com/castai/terraform-provider-castai/castai/sdk" | ||
| "github.com/hashicorp/go-cty/cty" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
| "github.com/stretchr/testify/require" | ||
| "testing" | ||
| ) | ||
|
|
||
| func Test_dataSourceGKEPoliciesRead(t *testing.T) { | ||
| up, _ := gke.GetUserPolicy() | ||
| lbNeg, _ := gke.GetLoadBalancersNetworkEndpointGroupPolicy() | ||
| lbTbp, _ := gke.GetLoadBalancersTargetBackendPoolsPolicy() | ||
| lbUig, _ := gke.GetLoadBalancersUnmanagedInstanceGroupsPolicy() | ||
| tests := []struct { | ||
| name string | ||
| features []interface{} | ||
| expected int | ||
| hasError bool | ||
| }{ | ||
| { | ||
| name: "all features", | ||
| features: []interface{}{ | ||
| loadBalancersNetworkEndpointGroupFeature, | ||
| loadBalancersTargetBackendPoolsFeature, | ||
| loadBalancersUnmanagedInstanceGroupsFeature, | ||
| }, | ||
| expected: len(up) + len(lbNeg) + len(lbTbp) + len(lbUig) - 1, // -1 for the duplicate policy | ||
| hasError: false, | ||
| }, | ||
| { | ||
| name: "empty features", | ||
| expected: len(up), | ||
| hasError: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| r := require.New(t) | ||
| //mockClient := mock_sdk.NewMockClientInterface(gomock.NewController(t)) | ||
|
|
||
| ctx := context.Background() | ||
| provider := &ProviderConfig{ | ||
| api: &sdk.ClientWithResponses{ | ||
| ClientInterface: nil, | ||
| }, | ||
| } | ||
|
|
||
| state := terraform.NewInstanceStateShimmedFromValue(cty.ObjectVal(map[string]cty.Value{}), 0) | ||
|
|
||
| resource := dataSourceGKEPolicies() | ||
| data := resource.Data(state) | ||
| r.NoError(data.Set(fieldGKEPoliciesFeatures, tt.features)) | ||
|
|
||
| result := resource.ReadContext(ctx, data, provider) | ||
| if tt.hasError { | ||
| r.True(result.HasError()) | ||
| } else { | ||
| r.Nil(result) | ||
| r.False(result.HasError()) | ||
| actualPolicies := data.Get(fieldGKEPoliciesPolicy).([]interface{}) | ||
| r.Len(actualPolicies, tt.expected) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestAccDataSourceGKEPolicies_basic(t *testing.T) { | ||
| resource.Test(t, resource.TestCase{ | ||
| PreCheck: func() { testAccPreCheck(t) }, | ||
| ProviderFactories: providerFactories, | ||
| CheckDestroy: nil, | ||
| Steps: []resource.TestStep{ | ||
| { | ||
| Config: testAccDataSourceGKEPoliciesConfig, | ||
| Check: resource.ComposeTestCheckFunc( | ||
| resource.TestCheckResourceAttr("data.castai_gke_user_policies.gke", "features.#", "3"), | ||
| resource.TestCheckResourceAttr("data.castai_gke_user_policies.gke", "policy.#", "46"), | ||
| ), | ||
| }, | ||
| { | ||
| Config: testAccDataSourceGKEPoliciesConfigUpdated, | ||
| Check: resource.ComposeTestCheckFunc( | ||
| resource.TestCheckResourceAttr("data.castai_gke_user_policies.gke", "features.#", "2"), | ||
| resource.TestCheckResourceAttr("data.castai_gke_user_policies.gke", "policy.#", "43ß"), | ||
| ), | ||
| }, | ||
| }, | ||
ValyaB marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }) | ||
| } | ||
|
|
||
| const testAccDataSourceGKEPoliciesConfig = ` | ||
| data "castai_gke_user_policies" "gke" { | ||
| features = [ | ||
| "load_balancers_network_endpoint_group", | ||
| "load_balancers_target_backend_pools", | ||
| "load_balancers_unmanaged_instance_groups" | ||
| ] | ||
| } | ||
| ` | ||
| const testAccDataSourceGKEPoliciesConfigUpdated = ` | ||
| data "castai_gke_user_policies" "gke" { | ||
| features = [ | ||
| "load_balancers_network_endpoint_group", | ||
| "load_balancers_target_backend_pools" | ||
| ] | ||
| } | ||
| ` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Policies": [ | ||
| "compute.networkEndpointGroups.get", | ||
| "compute.networkEndpointGroups.list", | ||
| "compute.networkEndpointGroups.attachNetworkEndpoints", | ||
| "compute.networkEndpointGroups.detachNetworkEndpoints" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Policies": [ | ||
| "compute.targetPools.get", | ||
| "compute.targetPools.addInstance", | ||
| "compute.targetPools.removeInstance", | ||
| "compute.instances.use" | ||
| ] | ||
| } |
6 changes: 6 additions & 0 deletions
6
castai/policies/gke/loadBalancers-unmanagedInstanceGroups.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "Policies": [ | ||
| "compute.instanceGroups.update", | ||
| "compute.instances.use" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.