forked from Azure/aks-engine
/
mocks.go
154 lines (135 loc) · 5.87 KB
/
mocks.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
package api
import (
"github.com/Azure/go-autorest/autorest/to"
"github.com/gofrs/uuid"
)
// CreateMockAgentPoolProfile creates a mock AgentPoolResource for testing
func CreateMockAgentPoolProfile(agentPoolName, orchestratorVersion string, provisioningState ProvisioningState, agentCount int) *AgentPoolResource {
agentPoolResource := AgentPoolResource{}
agentPoolResource.ID = uuid.Must(uuid.NewV4()).String()
agentPoolResource.Location = "westus2"
agentPoolResource.Name = agentPoolName
agentPoolResource.Properties = &AgentPoolProfile{}
// AgentPoolProfile needs to be remain same, so the name is repeated inside.
agentPoolResource.Properties.Name = agentPoolName
agentPoolResource.Properties.Count = agentCount
agentPoolResource.Properties.OrchestratorVersion = orchestratorVersion
agentPoolResource.Properties.ProvisioningState = provisioningState
return &agentPoolResource
}
// CreateMockContainerService returns a mock container service for testing purposes
func CreateMockContainerService(containerServiceName, orchestratorVersion string, masterCount, agentCount int, certs bool) *ContainerService {
cs := ContainerService{}
cs.ID = uuid.Must(uuid.NewV4()).String()
cs.Location = "eastus"
cs.Name = containerServiceName
cs.Properties = &Properties{}
cs.Properties.MasterProfile = &MasterProfile{}
cs.Properties.MasterProfile.Count = masterCount
cs.Properties.MasterProfile.DNSPrefix = "testmaster"
cs.Properties.MasterProfile.VMSize = "Standard_D2_v2"
cs.Properties.AgentPoolProfiles = []*AgentPoolProfile{}
agentPool := &AgentPoolProfile{}
agentPool.Count = agentCount
agentPool.Name = "agentpool1"
agentPool.VMSize = "Standard_D2_v2"
agentPool.OSType = "Linux"
agentPool.AvailabilityProfile = "AvailabilitySet"
agentPool.StorageProfile = "StorageAccount"
cs.Properties.AgentPoolProfiles = append(cs.Properties.AgentPoolProfiles, agentPool)
cs.Properties.LinuxProfile = &LinuxProfile{
AdminUsername: "azureuser",
SSH: struct {
PublicKeys []PublicKey `json:"publicKeys"`
}{},
}
cs.Properties.LinuxProfile.AdminUsername = "azureuser"
cs.Properties.LinuxProfile.SSH.PublicKeys = append(
cs.Properties.LinuxProfile.SSH.PublicKeys, PublicKey{KeyData: "test"})
cs.Properties.ServicePrincipalProfile = &ServicePrincipalProfile{}
cs.Properties.ServicePrincipalProfile.ClientID = "DEC923E3-1EF1-4745-9516-37906D56DEC4"
cs.Properties.ServicePrincipalProfile.Secret = "DEC923E3-1EF1-4745-9516-37906D56DEC4"
cs.Properties.OrchestratorProfile = &OrchestratorProfile{}
cs.Properties.OrchestratorProfile.OrchestratorType = Kubernetes
cs.Properties.OrchestratorProfile.OrchestratorVersion = orchestratorVersion
cs.Properties.OrchestratorProfile.KubernetesConfig = &KubernetesConfig{
EnableSecureKubelet: to.BoolPtr(DefaultSecureKubeletEnabled),
EnableRbac: to.BoolPtr(DefaultRBACEnabled),
EtcdDiskSizeGB: DefaultEtcdDiskSize,
ServiceCIDR: DefaultKubernetesServiceCIDR,
DockerBridgeSubnet: DefaultDockerBridgeSubnet,
DNSServiceIP: DefaultKubernetesDNSServiceIP,
GCLowThreshold: DefaultKubernetesGCLowThreshold,
GCHighThreshold: DefaultKubernetesGCHighThreshold,
MaxPods: DefaultKubernetesMaxPodsVNETIntegrated,
ClusterSubnet: DefaultKubernetesSubnet,
ContainerRuntime: DefaultContainerRuntime,
NetworkPlugin: DefaultNetworkPlugin,
NetworkPolicy: DefaultNetworkPolicy,
EtcdVersion: DefaultEtcdVersion,
MobyVersion: DefaultMobyVersion,
KubeletConfig: make(map[string]string),
}
cs.Properties.CertificateProfile = &CertificateProfile{}
if certs {
cs.Properties.CertificateProfile.CaCertificate = "cacert"
cs.Properties.CertificateProfile.CaPrivateKey = "cakey"
cs.Properties.CertificateProfile.KubeConfigCertificate = "kubeconfigcert"
cs.Properties.CertificateProfile.KubeConfigPrivateKey = "kubeconfigkey"
cs.Properties.CertificateProfile.APIServerCertificate = "apiservercert"
cs.Properties.CertificateProfile.APIServerPrivateKey = "apiserverkey"
cs.Properties.CertificateProfile.ClientCertificate = "clientcert"
cs.Properties.CertificateProfile.ClientPrivateKey = "clientkey"
cs.Properties.CertificateProfile.EtcdServerCertificate = "etcdservercert"
cs.Properties.CertificateProfile.EtcdServerPrivateKey = "etcdserverkey"
cs.Properties.CertificateProfile.EtcdClientCertificate = "etcdclientcert"
cs.Properties.CertificateProfile.EtcdClientPrivateKey = "etcdclientkey"
cs.Properties.CertificateProfile.EtcdPeerCertificates = []string{"etcdpeercert1", "etcdpeercert2", "etcdpeercert3", "etcdpeercert4", "etcdpeercert5"}
cs.Properties.CertificateProfile.EtcdPeerPrivateKeys = []string{"etcdpeerkey1", "etcdpeerkey2", "etcdpeerkey3", "etcdpeerkey4", "etcdpeerkey5"}
}
return &cs
}
// GetK8sDefaultProperties returns a struct of type api.Properties for testing purposes.
func GetK8sDefaultProperties(hasWindows bool) *Properties {
p := &Properties{
OrchestratorProfile: &OrchestratorProfile{
OrchestratorType: Kubernetes,
KubernetesConfig: &KubernetesConfig{},
},
MasterProfile: &MasterProfile{
Count: 1,
DNSPrefix: "foo",
VMSize: "Standard_DS2_v2",
},
AgentPoolProfiles: []*AgentPoolProfile{
{
Name: "agentpool",
VMSize: "Standard_D2_v2",
Count: 1,
AvailabilityProfile: AvailabilitySet,
},
},
ServicePrincipalProfile: &ServicePrincipalProfile{
ClientID: "clientID",
Secret: "clientSecret",
},
}
if hasWindows {
p.AgentPoolProfiles = []*AgentPoolProfile{
{
Name: "agentpool",
VMSize: "Standard_D2_v2",
Count: 1,
AvailabilityProfile: AvailabilitySet,
OSType: Windows,
},
}
p.WindowsProfile = &WindowsProfile{
AdminUsername: "azureuser",
AdminPassword: "replacepassword1234$",
}
}
return p
}