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

OCM-11845 | fix : wif-enable gcp-inquiries #673

Merged
merged 1 commit into from
Oct 15, 2024
Merged
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
4 changes: 2 additions & 2 deletions cmd/ocm/create/cluster/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,7 @@ func promptExistingGCPVPC(fs *pflag.FlagSet, connection *sdk.Connection) error {
if !useSharedVpc {
//get vpc's from the provider
vpcList, err := provider.GetGCPVPCs(connection.ClustersMgmt().V1(),
args.ccs, args.region)
args.ccs, args.gcpAuthentication, args.region)
if err != nil {
return err
}
Expand All @@ -1252,7 +1252,7 @@ func promptExistingGCPVPC(fs *pflag.FlagSet, connection *sdk.Connection) error {

//get subnets from the provider
subnetList, err := provider.GetGCPSubnetList(connection.ClustersMgmt().V1(), args.provider,
args.ccs, args.region)
args.ccs, args.gcpAuthentication, args.region)
if err != nil {
return err
}
Expand Down
27 changes: 21 additions & 6 deletions pkg/provider/subnetworks.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,32 @@ func getAWSVPCs(client *cmv1.Client, ccs cluster.CCS,
}

func GetGCPVPCs(client *cmv1.Client, ccs cluster.CCS,
region string) (cloudVPCList []*cmv1.CloudVPC, err error) {
gcpAuth cluster.GcpAuthentication, region string) (cloudVPCList []*cmv1.CloudVPC, err error) {

cloudProviderData, err := cmv1.NewCloudProviderData().
GCP(cmv1.NewGCP().ProjectID(ccs.GCP.ProjectID).
gcpBuilder := cmv1.NewGCP()

switch gcpAuth.Type {
case cluster.AuthenticationWif:
gcpAuth := cmv1.NewGcpAuthentication().
Kind(cmv1.WifConfigKind).
Id(gcpAuth.Id)
gcpBuilder.Authentication(gcpAuth)
case cluster.AuthenticationKey:
gcpBuilder.ProjectID(ccs.GCP.ProjectID).
ClientEmail(ccs.GCP.ClientEmail).
Type(ccs.GCP.Type).
PrivateKey(ccs.GCP.PrivateKey).
PrivateKeyID(ccs.GCP.PrivateKeyID).
AuthProviderX509CertURL(ccs.GCP.AuthProviderX509CertURL).
AuthURI(ccs.GCP.AuthURI).TokenURI(ccs.GCP.TokenURI).
ClientX509CertURL(ccs.GCP.ClientX509CertURL).
ClientID(ccs.GCP.ClientID).TokenURI(ccs.GCP.TokenURI)).
ClientID(ccs.GCP.ClientID).TokenURI(ccs.GCP.TokenURI)
default:
return nil, fmt.Errorf("Failed to build GCP provider data, unexpected GCP authentication method %q", gcpAuth.Type)
}

cloudProviderData, err := cmv1.NewCloudProviderData().
GCP(gcpBuilder).
Region(cmv1.NewCloudRegion().ID(region)).
Build()
if err != nil {
Expand Down Expand Up @@ -73,9 +87,10 @@ func GetAWSSubnetworks(client *cmv1.Client, ccs cluster.CCS,
}

func GetGCPSubnetList(client *cmv1.Client, provider string, ccs cluster.CCS,
region string) (subnetList []string, err error) {
gcpAuth cluster.GcpAuthentication, region string) (subnetList []string, err error) {
if ccs.Enabled && provider == "gcp" {
cloudVPCs, err := GetGCPVPCs(client, ccs, region)

cloudVPCs, err := GetGCPVPCs(client, ccs, gcpAuth, region)
if err != nil {
return nil, err
}
Expand Down
Loading