Skip to content

Commit

Permalink
verify if ID is present in Status before returning it to avoid nil po…
Browse files Browse the repository at this point in the history
…inter issue
  • Loading branch information
Amulyam24 committed May 3, 2024
1 parent 910b331 commit de208c6
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 @@ -815,6 +815,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 @@ -1106,6 +1109,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 @@ -1746,8 +1752,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 de208c6

Please sign in to comment.