Skip to content

Commit

Permalink
verify if ID is present before using it (#1733)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amulyam24 committed May 6, 2024
1 parent 14ccbde commit 81e93e2
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cloud/scope/powervs_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,9 @@ func (s *PowerVSClusterScope) getNetwork() (*string, error) {
// isDHCPServerActive checks if the DHCP server status is active.
func (s *PowerVSClusterScope) isDHCPServerActive() (bool, error) {
dhcpID := *s.GetDHCPServerID()
if dhcpID == "" {
return false, fmt.Errorf("DHCP ID is nil")
}
dhcpServer, err := s.IBMPowerVSClient.GetDHCPServer(dhcpID)
if err != nil {
return false, err
Expand Down Expand Up @@ -1128,6 +1131,9 @@ func (s *PowerVSClusterScope) createVPCSubnet(subnet infrav1beta2.Subnet) (*stri

// create subnet
vpcID := s.GetVPCID()
if vpcID == nil {
return nil, fmt.Errorf("VPC ID is nil")
}
cidrBlock, err := s.IBMVPCClient.GetSubnetAddrPrefix(*vpcID, zone)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1760,8 +1766,12 @@ func (s *PowerVSClusterScope) getVPCRegion() *string {

// fetchVPCCRN returns VPC CRN.
func (s *PowerVSClusterScope) fetchVPCCRN() (*string, error) {
vpcID := s.GetVPCID()
if vpcID == nil {
return nil, fmt.Errorf("VPC ID is nil")
}
vpcDetails, _, err := s.IBMVPCClient.GetVPC(&vpcv1.GetVPCOptions{
ID: s.GetVPCID(),
ID: vpcID,
})
if err != nil {
return nil, err
Expand Down

0 comments on commit 81e93e2

Please sign in to comment.