Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sku version logging #2412

Merged
merged 1 commit into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this one meant to merge before or after #2388 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way should be fine, they're independent (although rebases may happen). I'd like to see #2388 merge soon because it fixes a serious bug, but this just improves logging.

// 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