Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions pkg/asset/manifests/cloudproviderconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,28 @@ func (cpc *CloudProviderConfig) Generate(ctx context.Context, dependencies asset
}
}

projectID := installConfig.Config.Platform.GCP.ProjectID
if networkProjectID := installConfig.Config.Platform.GCP.NetworkProjectID; networkProjectID != "" {
projectID = networkProjectID
}

hasFirewallRules, err := gcp.HasPermissions(ctx, projectID, []string{gcp.CreateGCPFirewallPermission, gcp.DeleteGCPFirewallPermission})
if err != nil {
return fmt.Errorf("failed to determine user firewall permissions: %w", err)
}
firewallManagement := "Enabled"
if !hasFirewallRules {
firewallManagement = "Disabled"
}

gcpConfig, err := gcpmanifests.CloudProviderConfig(
clusterID.InfraID,
installConfig.Config.GCP.ProjectID,
subnet,
installConfig.Config.GCP.NetworkProjectID,
apiEndpoint,
containerAPIEndpoint,
firewallManagement,
)
if err != nil {
return errors.Wrap(err, "could not create cloud provider config")
Expand Down
7 changes: 6 additions & 1 deletion pkg/asset/manifests/gcp/cloudproviderconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ type global struct {
// ContainerAPIEndpoint is the container API endpoint to use. If this is blank,
// then the default endpoint is used.
ContainerAPIEndpoint string `gcfg:"container-api-endpoint"`

FirewallManagement string `gcfg:"firewall-rules-management"`
}

// CloudProviderConfig generates the cloud provider config for the GCP platform.
func CloudProviderConfig(infraID, projectID, subnet, networkProjectID, apiEndpoint, containerAPIEndpoint string) (string, error) {
func CloudProviderConfig(infraID, projectID, subnet, networkProjectID, apiEndpoint, containerAPIEndpoint, firewallManagement string) (string, error) {
config := &config{
Global: global{
ProjectID: projectID,
Expand All @@ -58,6 +60,8 @@ func CloudProviderConfig(infraID, projectID, subnet, networkProjectID, apiEndpoi
// Used for api endpoint overrides in the cloud provider.
APIEndpoint: apiEndpoint,
ContainerAPIEndpoint: containerAPIEndpoint,

FirewallManagement: firewallManagement,
},
}

Expand All @@ -82,5 +86,6 @@ subnetwork-name = {{.Global.SubnetworkName}}
{{- if ne .Global.NetworkProjectID "" }}{{"\n"}}network-project-id = {{.Global.NetworkProjectID}}{{ end }}
{{- if ne .Global.APIEndpoint "" }}{{"\n"}}api-endpoint = {{.Global.APIEndpoint}}{{ end }}
{{- if ne .Global.ContainerAPIEndpoint "" }}{{"\n"}}container-api-endpoint = {{.Global.ContainerAPIEndpoint}}{{ end }}
{{- if ne .Global.FirewallManagement "" }}{{"\n"}}firewall-rules-management = {{.Global.FirewallManagement}}{{ end }}

`
9 changes: 6 additions & 3 deletions pkg/asset/manifests/gcp/cloudproviderconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ node-tags = uid-worker
node-instance-prefix = uid
external-instance-groups-prefix = uid
subnetwork-name = uid-worker-subnet
firewall-rules-management = Enabled

`
actualConfig, err := CloudProviderConfig("uid", "test-project-id", "uid-worker-subnet", "", "", "")
actualConfig, err := CloudProviderConfig("uid", "test-project-id", "uid-worker-subnet", "", "", "", "Enabled")
assert.NoError(t, err, "failed to create cloud provider config")
assert.Equal(t, expectedConfig, actualConfig, "unexpected cloud provider config")
}
Expand All @@ -36,9 +37,10 @@ node-instance-prefix = uid
external-instance-groups-prefix = uid
subnetwork-name = uid-worker-subnet
network-project-id = test-network-project-id
firewall-rules-management = Enabled

`
actualConfig, err := CloudProviderConfig("uid", "test-project-id", "uid-worker-subnet", "test-network-project-id", "", "")
actualConfig, err := CloudProviderConfig("uid", "test-project-id", "uid-worker-subnet", "test-network-project-id", "", "", "Enabled")
assert.NoError(t, err, "failed to create cloud provider config")
assert.Equal(t, expectedConfig, actualConfig, "unexpected cloud provider config")
}
Expand All @@ -56,9 +58,10 @@ external-instance-groups-prefix = uid
subnetwork-name = uid-worker-subnet
api-endpoint = compute-testendpoint.p.googleapis.com
container-api-endpoint = container-testendpoint.p.googleapis.com
firewall-rules-management = Enabled

`
actualConfig, err := CloudProviderConfig("uid", "test-project-id", "uid-worker-subnet", "", "compute-testendpoint.p.googleapis.com", "container-testendpoint.p.googleapis.com")
actualConfig, err := CloudProviderConfig("uid", "test-project-id", "uid-worker-subnet", "", "compute-testendpoint.p.googleapis.com", "container-testendpoint.p.googleapis.com", "Enabled")
assert.NoError(t, err, "failed to create cloud provider config")
assert.Equal(t, expectedConfig, actualConfig, "unexpected cloud provider config")
}