Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
20 changes: 10 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ require (
github.com/Azure/go-autorest/autorest v0.11.29
github.com/Azure/go-autorest/autorest/to v0.4.0
github.com/IBM-Cloud/bluemix-go v0.0.0-20211102075456-ffc4e11dfb16
github.com/IBM-Cloud/power-go-client v1.2.0
github.com/IBM/go-sdk-core/v5 v5.13.2
github.com/IBM-Cloud/power-go-client v1.5.3
github.com/IBM/go-sdk-core/v5 v5.14.1
github.com/IBM/networking-go-sdk v0.42.2
github.com/IBM/platform-services-go-sdk v0.42.0
github.com/IBM/vpc-go-sdk v0.20.0
Expand All @@ -32,9 +32,9 @@ require (
github.com/daixiang0/gci v0.9.0
github.com/diskfs/go-diskfs v1.4.0
github.com/form3tech-oss/jwt-go v3.2.3+incompatible
github.com/go-openapi/errors v0.20.3
github.com/go-openapi/strfmt v0.21.5
github.com/go-openapi/swag v0.22.3
github.com/go-openapi/errors v0.20.4
github.com/go-openapi/strfmt v0.21.7
github.com/go-openapi/swag v0.22.4
github.com/go-playground/validator/v10 v10.13.0
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/golang/mock v1.7.0-rc.1
Expand Down Expand Up @@ -151,13 +151,13 @@ require (
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-logr/zapr v1.2.4 // indirect
github.com/go-openapi/analysis v0.21.2 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/loads v0.21.1 // indirect
github.com/go-openapi/runtime v0.23.0 // indirect
github.com/go-openapi/spec v0.20.7 // indirect
github.com/go-openapi/validate v0.22.0 // indirect
github.com/go-openapi/loads v0.21.2 // indirect
github.com/go-openapi/runtime v0.26.0 // indirect
github.com/go-openapi/spec v0.20.8 // indirect
github.com/go-openapi/validate v0.22.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/gobuffalo/flect v1.0.2 // indirect
Expand Down
85 changes: 23 additions & 62 deletions go.sum

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions pkg/asset/installconfig/platformprovisioncheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ func (a *PlatformProvisionCheck) Generate(dependencies asset.Parents) error {
return err
}

err = powervsconfig.ValidatePERAvailability(client, ic.Config)
if err != nil {
return err
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't need to be addressed in this PR, but maybe powervs can follow the pattern of the other platforms and use a ValidateForProvisioning function that encapsulates all the different validations needed.

err = powervsconfig.ValidatePreExistingDNS(client, ic.Config, ic.PowerVS)
if err != nil {
return err
Expand Down
19 changes: 19 additions & 0 deletions pkg/asset/installconfig/powervs/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/IBM-Cloud/bluemix-go/crn"
"github.com/IBM-Cloud/power-go-client/power/client/datacenters"
"github.com/IBM/go-sdk-core/v5/core"
"github.com/IBM/networking-go-sdk/dnsrecordsv1"
"github.com/IBM/networking-go-sdk/dnssvcsv1"
Expand Down Expand Up @@ -40,6 +41,7 @@ type API interface {
ListResourceGroups(ctx context.Context) (*resourcemanagerv2.ResourceGroupList, error)
ListServiceInstances(ctx context.Context) ([]string, error)
ServiceInstanceIDToCRN(ctx context.Context, id string) (string, error)
GetDatacenterCapabilities(ctx context.Context, region string) (map[string]bool, error)
}

// Client makes calls to the PowerVS API.
Expand Down Expand Up @@ -746,3 +748,20 @@ func (c *Client) ServiceInstanceIDToCRN(ctx context.Context, id string) (string,

return "", nil
}

// GetDatacenterCapabilities retrieves the capabilities of the specified datacenter.
func (c *Client) GetDatacenterCapabilities(ctx context.Context, region string) (map[string]bool, error) {
var err error
if c.BXCli.PISession == nil {
err = c.BXCli.NewPISession()
if err != nil {
return nil, fmt.Errorf("failed to initialize PISession in GetDatacenterCapabilities: %w", err)
}
}
params := datacenters.NewV1DatacentersGetParamsWithContext(ctx).WithDatacenterRegion(region)
getOk, err := c.BXCli.PISession.Power.Datacenters.V1DatacentersGet(params)
if err != nil {
return nil, fmt.Errorf("failed to get datacenter capabilities: %w", err)
}
return getOk.Payload.Capabilities, nil
}
15 changes: 15 additions & 0 deletions pkg/asset/installconfig/powervs/mock/powervsclient_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions pkg/asset/installconfig/powervs/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ func validateMachinePool(fldPath *field.Path, machinePool *types.MachinePool) fi
return allErrs
}

// ValidatePERAvailability ensures the target datacenter has PER enabled.
func ValidatePERAvailability(client API, ic *types.InstallConfig) error {
capabilities, err := client.GetDatacenterCapabilities(context.TODO(), ic.PowerVS.Zone)
if err != nil {
return err
}
const per = "power-edge-router"
perAvail, ok := capabilities[per]
if !ok {
return fmt.Errorf("%s capability unknown at: %s", per, ic.PowerVS.Zone)
}
if !perAvail {
return fmt.Errorf("%s is not available at: %s", per, ic.PowerVS.Zone)
}

return nil
}

// ValidatePreExistingDNS ensures no pre-existing DNS record exists in the CIS
// DNS zone or IBM DNS zone for cluster's Kubernetes API.
func ValidatePreExistingDNS(client API, ic *types.InstallConfig, metadata MetadataAPI) error {
Expand Down
85 changes: 85 additions & 0 deletions pkg/asset/installconfig/powervs/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,23 @@ var (
ID: &validRG,
},
}
regionWithPER = "dal10"
regionWithoutPER = "foo99"
regionPERUnknown = "bah77"
mapWithPERFalse = map[string]bool{
"disaster-recover-site": true,
"power-edge-router": false,
"vpn-connections": true,
}
mapWithPERTrue = map[string]bool{
"disaster-recover-site": true,
"power-edge-router": true,
"vpn-connections": true,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

For completeness, a test case where "power-edge-router" is not available.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in the latest force-push. PTAL.

mapPERUnknown = map[string]bool{
"disaster-recover-site": true,
"power-vpn-connections": false,
}
)

func validInstallConfig() *types.InstallConfig {
Expand Down Expand Up @@ -471,6 +488,74 @@ func createComputes(numComputes int32, compute *machinev1.PowerVSMachineProvider
return computes
}

func TestValidatePERAvailability(t *testing.T) {
cases := []struct {
name string
edits editFunctions
errorMsg string
}{
{
name: "Region without PER",
edits: editFunctions{
func(ic *types.InstallConfig) {
ic.Platform.PowerVS.Zone = regionWithoutPER
},
},
errorMsg: fmt.Sprintf("power-edge-router is not available at: %s", regionWithoutPER),
},
{
name: "Region with PER",
edits: editFunctions{
func(ic *types.InstallConfig) {
ic.Platform.PowerVS.Zone = regionWithPER
},
},
errorMsg: "",
},
{
name: "Region with no PER availability info",
edits: editFunctions{
func(ic *types.InstallConfig) {
ic.Platform.PowerVS.Zone = regionPERUnknown
},
},
errorMsg: fmt.Sprintf("power-edge-router capability unknown at: %s", regionPERUnknown),
},
}
setMockEnvVars()

mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

powervsClient := mock.NewMockAPI(mockCtrl)

// Mocks: PER-absent region results in false
powervsClient.EXPECT().GetDatacenterCapabilities(gomock.Any(), regionWithoutPER).Return(mapWithPERFalse, nil)

// Mocks: PER-enabled region results in true
powervsClient.EXPECT().GetDatacenterCapabilities(gomock.Any(), regionWithPER).Return(mapWithPERTrue, nil)

// Mocks: PER-unknown region results in false
powervsClient.EXPECT().GetDatacenterCapabilities(gomock.Any(), regionPERUnknown).Return(mapPERUnknown, nil)

// Run tests
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
editedInstallConfig := validInstallConfig()
for _, edit := range tc.edits {
edit(editedInstallConfig)
}

aggregatedErrors := powervs.ValidatePERAvailability(powervsClient, editedInstallConfig)
if tc.errorMsg != "" {
assert.Regexp(t, tc.errorMsg, aggregatedErrors)
} else {
assert.NoError(t, aggregatedErrors)
}
})
}
}

func setMockEnvVars() {
os.Setenv("POWERVS_AUTH_FILEPATH", "./tmp/powervs/config.json")
os.Setenv("IBMID", "foo")
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading