Skip to content

Commit

Permalink
Add sku version logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mboersma committed Jun 23, 2022
1 parent 111897c commit 9526c04
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion azure/services/virtualmachineimages/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func newCache(auth azure.Authorizer) *Cache {
}
}

// GetCache either creates a new VM images cache or returns an existing one.
// GetCache either creates a new VM images cache or returns the existing one.
func GetCache(auth azure.Authorizer) (*Cache, error) {
var err error
doOnce.Do(func() {
Expand Down
14 changes: 9 additions & 5 deletions azure/services/virtualmachineimages/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s *Service) GetDefaultUbuntuImage(ctx context.Context, location, k8sVersio

osVersion := getUbuntuOSVersion(v.Major, v.Minor, v.Patch)
publisher, offer := azure.DefaultImagePublisherID, azure.DefaultImageOfferID
skuID, version, err := s.getDefaultImageSKUIDAndVersion(
skuID, version, err := s.getSKUAndVersion(
ctx, location, publisher, offer, k8sVersion, fmt.Sprintf("ubuntu-%s", osVersion))
if err != nil {
return nil, errors.Wrap(err, "failed to get default image")
Expand Down Expand Up @@ -90,7 +90,7 @@ func (s *Service) GetDefaultWindowsImage(ctx context.Context, location, k8sVersi
}

publisher, offer := azure.DefaultImagePublisherID, azure.DefaultWindowsImageOfferID
skuID, version, err := s.getDefaultImageSKUIDAndVersion(
skuID, version, err := s.getSKUAndVersion(
ctx, location, publisher, offer, k8sVersion, osAndVersion)
if err != nil {
return nil, errors.Wrap(err, "failed to get default image")
Expand All @@ -115,12 +115,14 @@ func (s *Service) GetDefaultWindowsImage(ctx context.Context, location, k8sVersi
return defaultImage, nil
}

// GetDefaultImageSKUID gets the SKU ID and version of the image to use for the provided version of Kubernetes.
// getSKUAndVersion gets the SKU ID and version of the image to use for the provided version of Kubernetes.
// note: osAndVersion is expected to be in the format of {os}-{version} (ex: ubuntu-2004 or windows-2022)
func (s *Service) getDefaultImageSKUIDAndVersion(ctx context.Context, location, publisher, offer, k8sVersion, osAndVersion string) (string, string, error) {
ctx, _, done := tele.StartSpanWithLogger(ctx, "virtualmachineimages.AzureClient.getDefaultImageSKUIDAndVersion")
func (s *Service) getSKUAndVersion(ctx context.Context, location, publisher, offer, k8sVersion, osAndVersion string) (string, string, error) {
ctx, log, done := tele.StartSpanWithLogger(ctx, "virtualmachineimages.Service.getSKUAndVersion")
defer done()

log.Info("Getting VM image SKU and version", "location", location, "publisher", publisher, "offer", offer, "k8sVersion", k8sVersion, "osAndVersion", osAndVersion)

v, err := semver.ParseTolerant(k8sVersion)
if err != nil {
return "", "", errors.Wrapf(err, "unable to parse Kubernetes version \"%s\" in spec, expected valid SemVer string", k8sVersion)
Expand Down Expand Up @@ -171,6 +173,8 @@ func (s *Service) getDefaultImageSKUIDAndVersion(ctx context.Context, location,
return "", "", errors.Errorf("no VM image found for publisher \"%s\" offer \"%s\" sku \"%s\" with Kubernetes version \"%s\"", publisher, offer, sku, k8sVersion)
}

log.Info("Found VM image SKU and version", "location", location, "publisher", publisher, "offer", offer, "sku", sku, "version", version)

return sku, version, nil
}

Expand Down
2 changes: 1 addition & 1 deletion azure/services/virtualmachineimages/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ func TestGetDefaultImageSKUID(t *testing.T) {
List(gomock.Any(), location, azure.DefaultImagePublisherID, offer, gomock.Any()).
Return(test.versions, nil)
}
id, version, err := svc.getDefaultImageSKUIDAndVersion(context.TODO(), location, azure.DefaultImagePublisherID,
id, version, err := svc.getSKUAndVersion(context.TODO(), location, azure.DefaultImagePublisherID,
offer, test.k8sVersion, test.osAndVersion)

g := NewWithT(t)
Expand Down

0 comments on commit 9526c04

Please sign in to comment.