Skip to content

Commit

Permalink
azure: Fix incorrect assignment of ImageId
Browse files Browse the repository at this point in the history
The image specified in the annotation was incorrectly overriding the
default cluster wide config.

Drive-by fix: fix var name for ConfigVerifier

Fixes: #2284

Signed-off-by: Pradipta Banerjee <pradipta.banerjee@gmail.com>
  • Loading branch information
bpradipt committed Feb 10, 2025
1 parent fd69dab commit b9de6a8
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/cloud-providers/azure/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,14 @@ func (p *azureProvider) CreateInstance(ctx context.Context, podName, sandboxID s
return nil, err
}

imageId := p.serviceConfig.ImageId

if spec.Image != "" {
logger.Printf("Choosing %s from annotation as the Azure Image for the PodVM image", spec.Image)
p.serviceConfig.ImageId = spec.Image
imageId = spec.Image
}

vmParameters, err := p.getVMParameters(instanceSize, diskName, cloudConfigData, sshBytes, instanceName, nicName)
vmParameters, err := p.getVMParameters(instanceSize, diskName, cloudConfigData, sshBytes, instanceName, nicName, imageId)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -300,8 +302,8 @@ func (p *azureProvider) Teardown() error {
}

func (p *azureProvider) ConfigVerifier() error {
ImageId := p.serviceConfig.ImageId
if len(ImageId) == 0 {
imageId := p.serviceConfig.ImageId
if len(imageId) == 0 {
return fmt.Errorf("ImageId is empty")
}

Expand Down Expand Up @@ -371,7 +373,7 @@ func (p *azureProvider) getResourceTags() map[string]*string {
return tags
}

func (p *azureProvider) getVMParameters(instanceSize, diskName, cloudConfig string, sshBytes []byte, instanceName, nicName string) (*armcompute.VirtualMachine, error) {
func (p *azureProvider) getVMParameters(instanceSize, diskName, cloudConfig string, sshBytes []byte, instanceName, nicName string, imageId string) (*armcompute.VirtualMachine, error) {
userDataB64 := base64.StdEncoding.EncodeToString([]byte(cloudConfig))

// Azure limits the base64 encrypted userData to 64KB.
Expand Down Expand Up @@ -406,11 +408,11 @@ func (p *azureProvider) getVMParameters(instanceSize, diskName, cloudConfig stri
}

imgRef := &armcompute.ImageReference{
ID: to.Ptr(p.serviceConfig.ImageId),
ID: to.Ptr(imageId),
}
if strings.HasPrefix(p.serviceConfig.ImageId, "/CommunityGalleries/") {
if strings.HasPrefix(imageId, "/CommunityGalleries/") {
imgRef = &armcompute.ImageReference{
CommunityGalleryImageID: to.Ptr(p.serviceConfig.ImageId),
CommunityGalleryImageID: to.Ptr(imageId),
}
}

Expand Down

0 comments on commit b9de6a8

Please sign in to comment.