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

Add policycontroller fields to fleet default configs for GKE Hub Feature resource #9426

Merged
merged 79 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 76 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
85298f1
Adding Terraform resources for Tenancy APIs in GKEHub
sahsagar-google Jul 19, 2023
05f9e1d
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Jul 20, 2023
d056843
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Jul 24, 2023
20fea52
Segregating MembershipBinding and MembershipRBACRoleBinding to keep t…
sahsagar-google Jul 24, 2023
672494c
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Aug 2, 2023
3a4cefa
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Aug 10, 2023
693aaff
Fixing the docu URIs
sahsagar-google Aug 10, 2023
1d65988
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Aug 11, 2023
d783ddd
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Aug 11, 2023
bc96cbb
Adding TF support for Tenancy API for Membership Binding
sahsagar-google Jul 24, 2023
f74ce0f
Adding dependent membership binding to the same commit chain
sahsagar-google Aug 11, 2023
e0c2212
Making Scope un-updatable and replacing hard coded project number wit…
sahsagar-google Aug 12, 2023
c77f8b2
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Aug 14, 2023
71c92e6
Making Scope RRBAC updatable
sahsagar-google Aug 15, 2023
2403caa
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Aug 15, 2023
308091c
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Aug 15, 2023
a0f99d5
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Aug 15, 2023
78c9611
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Aug 22, 2023
45ee3fc
Making Namespace immutable
sahsagar-google Aug 22, 2023
4852207
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Aug 24, 2023
79a8e93
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Aug 25, 2023
db46dd0
Adding update test cases
sahsagar-google Aug 25, 2023
1cb54db
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Aug 28, 2023
f574890
Removing all memberships field from Scope since it is no longer suppo…
sahsagar-google Aug 28, 2023
35ea32e
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Aug 29, 2023
dd80ce3
Removing all_memberships field for Scope from all test cases
sahsagar-google Aug 29, 2023
371905f
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Aug 30, 2023
ad76f8b
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Aug 30, 2023
3d51fc1
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Aug 31, 2023
61ed74c
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Sep 1, 2023
5dd7c9d
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Sep 6, 2023
db7d7d2
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Sep 11, 2023
b72eff4
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Sep 12, 2023
0093110
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Sep 18, 2023
cdccf65
Merge branch 'GoogleCloudPlatform:main' into main
sahsagar-google Sep 18, 2023
90c0545
Enabling Membership resource to be regionalized with global as defaul…
sahsagar-google Sep 19, 2023
d2b5993
Moving the test to be the first one in sequence to work-around the IA…
sahsagar-google Sep 19, 2023
999f595
Update mmv1/products/gkehub/Membership.yaml
sahsagar-google Sep 27, 2023
9e24547
Adding state migration for gke hub membership
sahsagar-google Sep 29, 2023
3b9d9dc
Update mmv1/templates/terraform/examples/gkehub_membership_regional.t…
sahsagar-google Oct 3, 2023
e94f51f
Adding fleet_default_member_config field to the Feature resource
sahsagar-google Oct 11, 2023
a36b481
Merge branch 'GoogleCloudPlatform:main' into membership
sahsagar-google Oct 11, 2023
9014730
Fixing the enum value in example
sahsagar-google Oct 11, 2023
626419a
Fixing lint error
sahsagar-google Oct 11, 2023
bc13d70
Merge branch 'GoogleCloudPlatform:main' into membership
sahsagar-google Oct 16, 2023
ea694b3
Temporary removal of skipIfVcr test flag for the tests to run in PR
sahsagar-google Oct 16, 2023
f213fb4
Temporary removal of skipIfVcr test flag for the tests to run in PR
sahsagar-google Oct 16, 2023
9025020
Removing unnecessary field spec from feature
sahsagar-google Oct 16, 2023
a0289a7
Changing feature id to servicemesh
sahsagar-google Oct 17, 2023
dcea2a9
Merge branch 'GoogleCloudPlatform:main' into membership
sahsagar-google Oct 17, 2023
8dc46ff
Merge branch 'GoogleCloudPlatform:main' into membership
sahsagar-google Oct 18, 2023
95afea4
Adding dependency of feature on servicemesh API
sahsagar-google Oct 18, 2023
fb631ba
Enabling mesh and gkehub APIs to be used in the tests
sahsagar-google Oct 18, 2023
d47e330
Temporary enabling services in the test project
sahsagar-google Oct 18, 2023
9fe8cf2
Merge branch 'membership' of https://github.com/sahsagar-google/magic…
tonyzhc Oct 30, 2023
6804f8b
Merge branch 'GoogleCloudPlatform:main' into membership
sahsagar-google Oct 31, 2023
f040865
Adding dependency of feature test on new project
sahsagar-google Oct 31, 2023
f28c92a
Add Policy Controller fleet default config and basic create test
tonyzhc Nov 1, 2023
df15015
Testing a few more newly-added fields
sahsagar-google Nov 1, 2023
49e3c48
Depending on Terraform test project
sahsagar-google Nov 1, 2023
ee893a3
Fix compile errors and add service related tests.
tonyzhc Nov 2, 2023
93a792b
Merge branch 'membership' of https://github.com/sahsagar-google/magic…
tonyzhc Nov 2, 2023
5ba7420
Skipping if VCR
sahsagar-google Nov 3, 2023
f29e3e6
Depending on the newly created project for the tests
sahsagar-google Nov 3, 2023
6908ae5
Adding service enablement for Anthos
sahsagar-google Nov 6, 2023
8d88d0d
Merge branch 'GoogleCloudPlatform:main' into membership
sahsagar-google Nov 6, 2023
97602e3
Fix incorrect test terraform code format and other incorrect feature …
tonyzhc Nov 6, 2023
095d066
Add custom expand/flatten field handlers for objects of type map<stri…
tonyzhc Nov 7, 2023
80ebf17
Add missing test back.
tonyzhc Nov 7, 2023
d0755d6
Merge branch 'membership' of https://github.com/sahsagar-google/magic…
tonyzhc Nov 7, 2023
92e3d7d
Merge branch 'main' of https://github.com/GoogleCloudPlatform/magic-m…
tonyzhc Nov 7, 2023
f5d37f6
Fix format of example config.
tonyzhc Nov 7, 2023
e84e63e
Improve test coverage for monitoring field.
tonyzhc Nov 7, 2023
6ccce5f
Save my work before trying out the Map type, as an Array of NestedObj…
tonyzhc Nov 9, 2023
dfb64cf
Fix default from API errors to prevent permadiff.
tonyzhc Nov 14, 2023
c9be31c
Restore test cases.
tonyzhc Nov 14, 2023
d7fb6e5
Add more examples.
tonyzhc Nov 14, 2023
3797ef9
Delete unused custom_expand functions.
tonyzhc Nov 14, 2023
d0d7d82
Remove PoCo API beta dependency.
tonyzhc Nov 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions mmv1/products/gkehub2/Feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ examples:
skip_test: true
primary_resource_name: 'fmt.Sprintf("configmanagement")'
primary_resource_id: 'feature'
- !ruby/object:Provider::Terraform::Examples
name: 'enable_fleet_default_member_config_policycontroller'
skip_test: true
Copy link
Member

Choose a reason for hiding this comment

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

@tonyzhc Hi, what's the main reason for skipping these? Were you able to test locally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test and the API dependencies don't work well with VCR tests. We instead covered them in the custom acceptance tests and added the skip VCR options. I have added more examples to serve the documentation purpose.

primary_resource_name: 'fmt.Sprintf("policycontroller")'
primary_resource_id: 'feature'
autogen_async: true
# Skip sweeper gen since this is a child resource.
skip_sweeper: true
Expand Down Expand Up @@ -259,6 +264,161 @@ properties:
- !ruby/object:Api::Type::String
name: version
description: 'Version of ACM installed'
- !ruby/object:Api::Type::NestedObject
name: policycontroller
description: Policy Controller spec
properties:
- !ruby/object:Api::Type::String
name: version
description: 'Configures the version of Policy Controller'
default_from_api: true
- !ruby/object:Api::Type::NestedObject
name: policyControllerHubConfig
description: 'Configuration of Policy Controller'
required: true
properties:
- !ruby/object:Api::Type::Enum
name: installSpec
description: 'Configures the mode of the Policy Controller installation'
values:
- :INSTALL_SPEC_UNSPECIFIED
- :INSTALL_SPEC_NOT_INSTALLED
- :INSTALL_SPEC_ENABLED
- :INSTALL_SPEC_SUSPENDED
- :INSTALL_SPEC_DETACHED
required: true
- !ruby/object:Api::Type::Integer
name: auditIntervalSeconds
description: 'Interval for Policy Controller Audit scans (in seconds). When set to 0, this disables audit functionality altogether.'
- !ruby/object:Api::Type::Array
name: exemptableNamespaces
description: 'The set of namespaces that are excluded from Policy Controller checks. Namespaces do not need to currently exist on the cluster.'
item_type: Api::Type::String
- !ruby/object:Api::Type::Boolean
name: logDeniesEnabled
description: 'Logs all denies and dry run failures.'
- !ruby/object:Api::Type::Boolean
name: mutationEnabled
description: 'Enables the ability to mutate resources using Policy Controller.'
- !ruby/object:Api::Type::Boolean
name: referentialRulesEnabled
description: 'Enables the ability to use Constraint Templates that reference to objects other than the object currently being evaluated.'
- !ruby/object:Api::Type::NestedObject
name: monitoring
description: 'Monitoring specifies the configuration of monitoring Policy Controller.'
default_from_api: true
properties:
- !ruby/object:Api::Type::Array
name: backends
description: 'Specifies the list of backends Policy Controller will export to. An empty list would effectively disable metrics export.'
default_from_api: true
item_type: !ruby/object:Api::Type::Enum
name: 'required but unused'
description: 'required but unused'
values:
- :MONITORING_BACKEND_UNSPECIFIED
- :PROMETHEUS
- :CLOUD_MONITORING
- !ruby/object:Api::Type::Integer
name: constraintViolationLimit
description: 'The maximum number of audit violations to be stored in a constraint. If not set, the internal default of 20 will be used.'
- !ruby/object:Api::Type::Map
name: deploymentConfigs
description: 'Map of deployment configs to deployments ("admission", "audit", "mutation").'
key_name: component
key_description: 'Specifies which component to apply the deployment config to. Accepted values are "admission", "audit" and "mutation".'
default_from_api: true
value_type: !ruby/object:Api::Type::NestedObject
name: deploymentConfig
description: 'Configures deployment-specific options, such as high availability.'
properties:
- !ruby/object:Api::Type::Integer
name: replicaCount
description: 'Pod replica count.'
send_empty_value: false
default_from_api: true
- !ruby/object:Api::Type::NestedObject
name: containerResources
description: 'Container resource requirements.'
properties:
- !ruby/object:Api::Type::NestedObject
name: limits
description: 'Limits describes the maximum amount of compute resources allowed for use by the running container.'
properties:
- !ruby/object:Api::Type::String
name: memory
description: 'Memory requirement expressed in Kubernetes resource units.'
- !ruby/object:Api::Type::String
name: cpu
description: 'CPU requirement expressed in Kubernetes resource units.'
- !ruby/object:Api::Type::NestedObject
name: requests
description: 'Requests describes the amount of compute resources reserved for the container by the kube-scheduler.'
properties:
- !ruby/object:Api::Type::String
name: memory
description: 'Memory requirement expressed in Kubernetes resource units.'
- !ruby/object:Api::Type::String
name: cpu
description: 'CPU requirement expressed in Kubernetes resource units.'
- !ruby/object:Api::Type::Enum
name: podAffinity
description: 'Pod affinity configuration.'
default_from_api: true
values:
- :AFFINITY_UNSPECIFIED
- :NO_AFFINITY
- :ANTI_AFFINITY
- !ruby/object:Api::Type::Array
name: podToleration
api_name: podTolerations
description: 'Pod tolerations of node taints.'
item_type: !ruby/object:Api::Type::NestedObject
name: 'required but unused'
description: 'required but unused'
properties:
- !ruby/object:Api::Type::String
name: key
description: 'Matches a taint key (not necessarily unique).'
- !ruby/object:Api::Type::String
name: operator
description: 'Matches a taint operator.'
- !ruby/object:Api::Type::String
name: value
description: 'Matches a taint value.'
- !ruby/object:Api::Type::String
name: effect
description: 'Matches a taint effect.'
- !ruby/object:Api::Type::NestedObject
name: policyContent
description: 'Specifies the desired policy content on the cluster.'
# default_from_api: true
properties:
- !ruby/object:Api::Type::NestedObject
name: templateLibrary
description: 'Configures the installation of the Template Library.'
default_from_api: true
properties:
- !ruby/object:Api::Type::Enum
name: installation
description: 'Configures the manner in which the template library is installed on the cluster.'
values:
- :INSTALATION_UNSPECIFIED
- :NOT_INSTALLED
- :ALL
- !ruby/object:Api::Type::Map
name: bundles
description: 'Configures which bundles to install and their corresponding install specs.'
key_name: bundle
key_description: 'A bundle name supported in this version. Values configure the exempted namespaces for this bundle.'
value_type: !ruby/object:Api::Type::NestedObject
name: bundleInstallSpec
description: 'The specification configuration for a single managed bundle.'
properties:
- !ruby/object:Api::Type::Array
name: exemptedNamespaces
description: 'The set of namespaces to be exempted from the bundle.'
item_type: Api::Type::String
- !ruby/object:Api::Type::NestedObject
name: state
description: Output only. The Hub-wide Feature state
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
if v == nil {
return nil, nil
}

m, ok := v.([]interface{})
if !ok {
return nil, fmt.Errorf("unable to convert %v to []interface{}", v)
}
req := make(map[string]interface{})
for _, raw := range m {
if raw == nil {
continue
}

deploymentConfig := raw.(map[string]interface{})
log.Printf("WTF*** config is: %v\n", deploymentConfig)
Copy link
Member

Choose a reason for hiding this comment

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

Haha, just to make sure, is this abbrev. 'What the feature,' correct?

componentName := deploymentConfig["component"].(string)
delete(deploymentConfig, "component")

if v, ok := deploymentConfig["pod_toleration"]; ok {
deploymentConfig["pod_tolerations"] = v
delete(deploymentConfig, "pod_toleration")
}

if v, ok := deploymentConfig["pod_affinity"]; ok {
pa := v.(string)
if pa == "" {
delete(deploymentConfig, "pod_affinity")
}
}

if v, ok := deploymentConfig["replica_count"]; ok {
rc := v.(int)
if rc == 0 {
delete(deploymentConfig, "replica_count")
}
}

// Somehow the container_resources field gets encoded unexpectedly into an array. Fix that.
if v, ok := deploymentConfig["container_resources"]; ok {
if arr, ok := v.([]interface{}); ok && len(arr) == 1 {
actualCR := arr[0].(map[string]interface{})
if l, ok := actualCR["limits"]; ok {
if lArr, ok := l.([]interface{}); ok && len(lArr) == 1 {
actualLimits := lArr[0].(map[string]interface{})
actualCR["limits"] = actualLimits
}
}
if r, ok := actualCR["requests"]; ok {
if rArr, ok := r.([]interface{}); ok && len(rArr) == 1 {
actualRequests := rArr[0].(map[string]interface{})
actualCR["requests"] = actualRequests
}
}
deploymentConfig["container_resources"] = actualCR
} else if ok && len(arr) == 0 {
delete(deploymentConfig, "container_resources")
}
}

req[componentName] = deploymentConfig
}

return req, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
func expand<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
if v == nil {
return nil, nil
}

m, ok := v.([]interface{})
if !ok {
return nil, fmt.Errorf("unable to convert %v to []interface{}", v)
}
req := make(map[string]interface{})
for _, raw := range m {
if raw == nil {
continue
}

bundleObj := raw.(map[string]interface{})
bundleName := bundleObj["name"].(string)
delete(bundleObj, "name")
req[bundleName] = bundleObj
}

return req, nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
resource "google_gke_hub_feature" "feature" {
name = "policycontroller"
location = "global"
fleet_default_member_config {
policycontroller {
policy_controller_hub_config {
install_spec = "INSTALL_SPEC_ENABLED"
exemptable_namespaces = ["foo"]
policy_content {
bundle {
name = "policy-essentials-v2022"
exempted_namespaces = ["foo", "bar"]
}
template_library {
installation = "ALL"
}
}
audit_interval_seconds = 30
referential_rules_enabled = true
}
}
}
}
Loading