Skip to content

Commit

Permalink
operator: refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
msanft committed Jan 24, 2024
1 parent 9c71c4d commit 37aaaab
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,31 @@ func (c *Client) GetNodeImage(ctx context.Context, providerID string) (string, e
resp.Properties.StorageProfile.ImageReference == nil ||
resp.Properties.StorageProfile.ImageReference.ID == nil &&
resp.Properties.StorageProfile.ImageReference.CommunityGalleryImageID == nil &&
resp.Properties.StorageProfile.ImageReference.Publisher == nil &&
resp.Properties.StorageProfile.ImageReference.Offer == nil &&
resp.Properties.StorageProfile.ImageReference.SKU == nil &&
resp.Properties.StorageProfile.ImageReference.Version == nil {
(resp.Properties.StorageProfile.ImageReference.Publisher == nil ||
resp.Properties.StorageProfile.ImageReference.Offer == nil ||
resp.Properties.StorageProfile.ImageReference.SKU == nil ||
resp.Properties.StorageProfile.ImageReference.Version == nil) {
return "", fmt.Errorf("node %q does not have valid image reference", providerID)
}

// Marketplace Image is used, format it to an URI and return it.
if resp.Properties.StorageProfile.ImageReference.Publisher != nil &&
resp.Properties.StorageProfile.ImageReference.Offer != nil &&
resp.Properties.StorageProfile.ImageReference.SKU != nil &&
resp.Properties.StorageProfile.ImageReference.Version != nil {
return mpimage.AzureMarketplaceImage{
Publisher: *resp.Properties.StorageProfile.ImageReference.Publisher,
Offer: *resp.Properties.StorageProfile.ImageReference.Offer,
SKU: *resp.Properties.StorageProfile.ImageReference.SKU,
Version: *resp.Properties.StorageProfile.ImageReference.Version,
}.URI(), nil
}

// Image ID is set, return it.
if resp.Properties.StorageProfile.ImageReference.ID != nil {
return *resp.Properties.StorageProfile.ImageReference.ID, nil
}

// Community Gallery image ID is set otherwise.
return *resp.Properties.StorageProfile.ImageReference.CommunityGalleryImageID, nil
// Community Gallery image ID is set, return it.
if resp.Properties.StorageProfile.ImageReference.CommunityGalleryImageID != nil {
return *resp.Properties.StorageProfile.ImageReference.CommunityGalleryImageID, nil
}

// Last possible option: Marketplace Image is used, format it to an URI and return it.
return mpimage.AzureMarketplaceImage{
Publisher: *resp.Properties.StorageProfile.ImageReference.Publisher,
Offer: *resp.Properties.StorageProfile.ImageReference.Offer,
SKU: *resp.Properties.StorageProfile.ImageReference.SKU,
Version: *resp.Properties.StorageProfile.ImageReference.Version,
}.URI(), nil

}

// GetScalingGroupID returns the scaling group ID of the node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,30 @@ func (c *Client) GetScalingGroupImage(ctx context.Context, scalingGroupID string
res.Properties.VirtualMachineProfile.StorageProfile.ImageReference == nil ||
res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.ID == nil &&
res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.CommunityGalleryImageID == nil &&
res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.Publisher == nil &&
res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.Offer == nil &&
res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.SKU == nil &&
res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.Version == nil {
(res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.Publisher == nil ||
res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.Offer == nil ||
res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.SKU == nil ||
res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.Version == nil) {
return "", fmt.Errorf("scalet set %q does not have valid image reference", scalingGroupID)
}

// Marketplace Image is used, format it to an URI and return it.
if res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.Publisher != nil &&
res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.Offer != nil &&
res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.SKU != nil &&
res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.Version != nil {
return mpimage.AzureMarketplaceImage{
Publisher: *res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.Publisher,
Offer: *res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.Offer,
SKU: *res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.SKU,
Version: *res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.Version,
}.URI(), nil
}

// Image ID is set, return it.
if res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.ID != nil {
return *res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.ID, nil
}

// Community Gallery Image ID is set otherwise.
return *res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.CommunityGalleryImageID, nil
// Community Gallery Image ID is set, return it.
if res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.CommunityGalleryImageID != nil {
return *res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.CommunityGalleryImageID, nil
}

// Last possible option: Marketplace Image is used, format it to an URI and return it.
return mpimage.AzureMarketplaceImage{
Publisher: *res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.Publisher,
Offer: *res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.Offer,
SKU: *res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.SKU,
Version: *res.Properties.VirtualMachineProfile.StorageProfile.ImageReference.Version,
}.URI(), nil
}

// SetScalingGroupImage sets the image URI of the scaling group.
Expand Down

0 comments on commit 37aaaab

Please sign in to comment.