This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 523
/
support_validator.go
114 lines (105 loc) · 3.49 KB
/
support_validator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
package armhelpers
import (
"context"
"fmt"
"github.com/Azure/aks-engine/pkg/api"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
)
type validationResult struct {
image api.AzureOSImageConfig
errorData error
}
// ValidateRequiredImages checks that the OS images required by both
// master and agent pools are available on the target cloud
func ValidateRequiredImages(ctx context.Context, location string, p *api.Properties, client AKSEngineClient) error {
if fetcher, ok := client.(VMImageFetcher); ok {
missingImages := make(map[api.Distro]validationResult)
for distro, i := range requiredImages(p) {
log.Debugln(fmt.Sprintf("Validate OS image is available on the target cloud: %s, %s, %s, %s", i.ImagePublisher, i.ImageOffer, i.ImageSku, i.ImageVersion))
if i.ImageVersion == "latest" {
list, err := fetcher.ListVirtualMachineImages(ctx, location, i.ImagePublisher, i.ImageOffer, i.ImageSku)
if err != nil || len(*list.Value) == 0 {
missingImages[distro] = validationResult{
image: i,
errorData: err,
}
}
} else {
if _, err := fetcher.GetVirtualMachineImage(ctx, location, i.ImagePublisher, i.ImageOffer, i.ImageSku, i.ImageVersion); err != nil {
missingImages[distro] = validationResult{
image: i,
errorData: err,
}
}
}
}
if len(missingImages) == 0 {
return nil
}
return printErrorIfAny(missingImages)
}
return errors.New("parameter client is not a VMImageFetcher")
}
func requiredImages(p *api.Properties) map[api.Distro]api.AzureOSImageConfig {
images := make(map[api.Distro]api.AzureOSImageConfig)
images[p.MasterProfile.Distro] = toImageConfig(p.MasterProfile.Distro)
for _, app := range p.AgentPoolProfiles {
if app.OSType == api.Windows {
images[app.Distro] = toImageConfigWindows(p.WindowsProfile)
} else {
images[app.Distro] = toImageConfig(app.Distro)
}
}
return images
}
func printErrorIfAny(missingImages map[api.Distro]validationResult) error {
for _, value := range missingImages {
i := value.image
log.Errorf("error: %+v", value.errorData)
log.Errorf("Image Publisher: %s, Offer: %s, SKU: %s, Version: %s", i.ImagePublisher, i.ImageOffer, i.ImageSku, i.ImageVersion)
}
return errors.New("some VM images are missing on the target cloud")
}
func toImageConfig(distro api.Distro) api.AzureOSImageConfig {
if distro == "" {
return api.Ubuntu1604OSImageConfig
}
switch distro {
case api.Ubuntu:
return api.Ubuntu1604OSImageConfig
case api.Ubuntu1804:
return api.Ubuntu1804OSImageConfig
case api.Ubuntu1804Gen2:
return api.Ubuntu1804Gen2OSImageConfig
case api.Ubuntu2004:
return api.Ubuntu2004OSImageConfig
case api.Ubuntu2004Gen2:
return api.Ubuntu2004Gen2OSImageConfig
case api.Flatcar:
return api.FlatcarImageConfig
case api.AKSUbuntu1604:
return api.AKSUbuntu1604OSImageConfig
case api.AKSUbuntu1804:
return api.AKSUbuntu1804OSImageConfig
case api.AKSUbuntu2004:
return api.AKSUbuntu2004OSImageConfig
case api.ACC1604:
return api.ACC1604OSImageConfig
default:
return api.Ubuntu1604OSImageConfig
}
}
func toImageConfigWindows(profile *api.WindowsProfile) api.AzureOSImageConfig {
if profile != nil {
return api.AzureOSImageConfig{
ImageOffer: profile.WindowsOffer,
ImageSku: profile.WindowsSku,
ImagePublisher: profile.WindowsPublisher,
ImageVersion: profile.ImageVersion,
}
}
return api.AKSWindowsServer2019ContainerDOSImageConfig
}