@@ -39,31 +39,31 @@ func NewMachineOSConfigList(oc *exutil.CLI) *MachineOSConfigList {
39
39
}
40
40
41
41
// CreateMachineOSConfig creates a MOSC resource using the information provided in the arguments
42
- func CreateMachineOSConfig (oc * exutil.CLI , name , pool , baseImagePullSecret , renderedImagePushSecret , pushSpec string , containerFile []ContainerFile ) (* MachineOSConfig , error ) {
43
- return createMachineOSConfig (oc , name , pool , & baseImagePullSecret , renderedImagePushSecret , pushSpec , containerFile )
42
+ func CreateMachineOSConfig (oc * exutil.CLI , moscAndMcpName , baseImagePullSecret , renderedImagePushSecret , pushSpec string , containerFile []ContainerFile ) (* MachineOSConfig , error ) {
43
+ return createMachineOSConfig (oc , moscAndMcpName , & baseImagePullSecret , renderedImagePushSecret , pushSpec , containerFile )
44
44
}
45
45
46
46
// CreateMachineOSConfigWithDefaultBasImagePullSecret creates a MOSC resource using the information provided in the arguments, it does not define the image pull secret
47
- func CreateMachineOSConfigWithDefaultBasImagePullSecret (oc * exutil.CLI , name , pool , renderedImagePushSecret , pushSpec string , containerFile []ContainerFile ) (* MachineOSConfig , error ) {
48
- return createMachineOSConfig (oc , name , pool , nil , renderedImagePushSecret , pushSpec , containerFile )
47
+ func CreateMachineOSConfigWithDefaultBasImagePullSecret (oc * exutil.CLI , moscAndMcpName , renderedImagePushSecret , pushSpec string , containerFile []ContainerFile ) (* MachineOSConfig , error ) {
48
+ return createMachineOSConfig (oc , moscAndMcpName , nil , renderedImagePushSecret , pushSpec , containerFile )
49
49
}
50
50
51
51
// createMachineOSConfig creates a MOSC resource using the information provided in the arguments
52
- func createMachineOSConfig (oc * exutil.CLI , name , pool string , baseImagePullSecret * string , renderedImagePushSecret , pushSpec string , containerFile []ContainerFile ) (* MachineOSConfig , error ) {
52
+ func createMachineOSConfig (oc * exutil.CLI , moscAndMcpName string , baseImagePullSecret * string , renderedImagePushSecret , pushSpec string , containerFile []ContainerFile ) (* MachineOSConfig , error ) {
53
53
var (
54
54
containerFilesString = "[]"
55
55
moscTemplateFile = "generic-machine-os-config-nobaseimagepull.yaml"
56
- parameters = []string {"-p" , "NAME=" + name , "POOL=" + pool ,
56
+ parameters = []string {"-p" , "NAME=" + moscAndMcpName , "POOL=" + moscAndMcpName ,
57
57
"RENDEREDIMAGEPUSHSECRET=" + renderedImagePushSecret , "PUSHSPEC=" + pushSpec }
58
58
)
59
59
if baseImagePullSecret != nil {
60
60
moscTemplateFile = "generic-machine-os-config.yaml"
61
61
parameters = append (parameters , "BASEIMAGEPULLSECRET=" + * baseImagePullSecret )
62
- logger .Infof ("Creating MachineOSConfig %s in pool %s with pullSecret %s pushSecret %s and pushSpec %s" , name , pool , * baseImagePullSecret , renderedImagePushSecret , pushSpec )
62
+ logger .Infof ("Creating MachineOSConfig %s in pool %s with pullSecret %s pushSecret %s and pushSpec %s" , moscAndMcpName , moscAndMcpName , * baseImagePullSecret , renderedImagePushSecret , pushSpec )
63
63
} else {
64
- logger .Infof ("Creating MachineOSConfig %s in pool %s with default pullSecret pushSecret %s and pushSpec %s" , name , pool , renderedImagePushSecret , pushSpec )
64
+ logger .Infof ("Creating MachineOSConfig %s in pool %s with default pullSecret pushSecret %s and pushSpec %s" , moscAndMcpName , moscAndMcpName , renderedImagePushSecret , pushSpec )
65
65
}
66
- newMOSC := NewMachineOSConfig (oc , name )
66
+ newMOSC := NewMachineOSConfig (oc , moscAndMcpName )
67
67
68
68
if len (containerFile ) > 0 {
69
69
containerFilesBytes , err := json .Marshal (containerFile )
@@ -103,15 +103,15 @@ func CopySecretToMCONamespace(secret *Secret, newName string) (*Secret, error) {
103
103
return & Secret {Resource : * mcoResource }, nil
104
104
}
105
105
106
- func CreateMachineOSConfigUsingInternalRegistry (oc * exutil.CLI , namespace , name , pool string , containerFile []ContainerFile , defaultPullSecret bool ) (* MachineOSConfig , error ) {
106
+ func CreateMachineOSConfigUsingInternalRegistry (oc * exutil.CLI , namespace , moscAndMcpName string , containerFile []ContainerFile , defaultPullSecret bool ) (* MachineOSConfig , error ) {
107
107
108
108
// We use the builder SA secret in the namespace to push the images to the internal registry
109
109
renderedImagePushSecret , err := CreateInternalRegistrySecretFromSA (oc , "builder" , namespace , "cloned-push-secret" + exutil .GetRandomString (), MachineConfigNamespace )
110
110
if err != nil {
111
- return NewMachineOSConfig (oc , name ), err
111
+ return NewMachineOSConfig (oc , moscAndMcpName ), err
112
112
}
113
113
if ! renderedImagePushSecret .Exists () {
114
- return NewMachineOSConfig (oc , name ), fmt .Errorf ("Rendered image push secret does not exist: %s" , renderedImagePushSecret )
114
+ return NewMachineOSConfig (oc , moscAndMcpName ), fmt .Errorf ("Rendered image push secret does not exist: %s" , renderedImagePushSecret )
115
115
}
116
116
117
117
if namespace != MachineConfigNamespace { // If the secret is not in MCO, we copy it there
@@ -120,71 +120,71 @@ func CreateMachineOSConfigUsingInternalRegistry(oc *exutil.CLI, namespace, name,
120
120
// We use the default SA secret in MCO to pull the current image from the internal registry
121
121
namespacedPullSecret , err := CreateInternalRegistrySecretFromSA (oc , "default" , namespace , "cloned-currentpull-secret" + exutil .GetRandomString (), namespace )
122
122
if err != nil {
123
- return NewMachineOSConfig (oc , name ), err
123
+ return NewMachineOSConfig (oc , moscAndMcpName ), err
124
124
}
125
125
if ! namespacedPullSecret .Exists () {
126
- return NewMachineOSConfig (oc , name ), fmt .Errorf ("Current image pull secret does not exist: %s" , namespacedPullSecret )
126
+ return NewMachineOSConfig (oc , moscAndMcpName ), fmt .Errorf ("Current image pull secret does not exist: %s" , namespacedPullSecret )
127
127
}
128
128
129
129
namespacedDockerConfig , err := namespacedPullSecret .GetDataValue (".dockerconfigjson" )
130
130
if err != nil {
131
- return NewMachineOSConfig (oc , name ), fmt .Errorf ("Could not extract dockerConfig from the namespaced pull secret" )
131
+ return NewMachineOSConfig (oc , moscAndMcpName ), fmt .Errorf ("Could not extract dockerConfig from the namespaced pull secret" )
132
132
}
133
133
134
134
pullSecret := GetPullSecret (oc .AsAdmin ())
135
135
pullSecretDockerConfig , err := pullSecret .GetDataValue (".dockerconfigjson" )
136
136
if err != nil {
137
- return NewMachineOSConfig (oc , name ), fmt .Errorf ("Could not extract dockerConfig from the cluster's pull secret" )
137
+ return NewMachineOSConfig (oc , moscAndMcpName ), fmt .Errorf ("Could not extract dockerConfig from the cluster's pull secret" )
138
138
}
139
139
140
140
mergedDockerConfig , err := MergeDockerConfigs (pullSecretDockerConfig , namespacedDockerConfig )
141
141
if err != nil {
142
- return NewMachineOSConfig (oc , name ), fmt .Errorf ("Could not merge the namespaced pull-secret dockerconfig and the cluster's pull-secret docker config" )
142
+ return NewMachineOSConfig (oc , moscAndMcpName ), fmt .Errorf ("Could not merge the namespaced pull-secret dockerconfig and the cluster's pull-secret docker config" )
143
143
}
144
144
145
145
err = pullSecret .SetDataValue (".dockerconfigjson" , mergedDockerConfig )
146
146
if err != nil {
147
- return NewMachineOSConfig (oc , name ), fmt .Errorf ("Could not configure the cluster's pull-secret with the merged dockerconfig" )
147
+ return NewMachineOSConfig (oc , moscAndMcpName ), fmt .Errorf ("Could not configure the cluster's pull-secret with the merged dockerconfig" )
148
148
}
149
149
150
150
logger .Infof ("Waiting for the secret to be updated in all pools" )
151
151
NewMachineConfigPoolList (oc .AsAdmin ()).waitForComplete ()
152
152
}
153
153
154
154
// We use a push spec stored in the internal registry in the MCO namespace. We use a different image for every pool
155
- pushSpec := fmt .Sprintf ("%s/%s/ocb-%s-image:latest" , InternalRegistrySvcURL , namespace , pool )
155
+ pushSpec := fmt .Sprintf ("%s/%s/ocb-%s-image:latest" , InternalRegistrySvcURL , namespace , moscAndMcpName )
156
156
157
157
if ! defaultPullSecret {
158
158
// We use a copy of the cluster's pull secret to pull the images
159
159
pullSecret := NewSecret (oc .AsAdmin (), "openshift-config" , "pull-secret" )
160
160
baseImagePullSecret , err := CopySecretToMCONamespace (pullSecret , "cloned-basepull-secret-" + exutil .GetRandomString ())
161
161
if err != nil {
162
- return NewMachineOSConfig (oc , name ), err
162
+ return NewMachineOSConfig (oc , moscAndMcpName ), err
163
163
}
164
- return CreateMachineOSConfig (oc , name , pool , baseImagePullSecret .GetName (), renderedImagePushSecret .GetName (), pushSpec , containerFile )
164
+ return CreateMachineOSConfig (oc , moscAndMcpName , baseImagePullSecret .GetName (), renderedImagePushSecret .GetName (), pushSpec , containerFile )
165
165
}
166
166
167
- return CreateMachineOSConfigWithDefaultBasImagePullSecret (oc , name , pool , renderedImagePushSecret .GetName (), pushSpec , containerFile )
167
+ return CreateMachineOSConfigWithDefaultBasImagePullSecret (oc , moscAndMcpName , renderedImagePushSecret .GetName (), pushSpec , containerFile )
168
168
}
169
169
170
170
// CreateMachineOSConfigUsingExternalRegistry creates a new MOSC resource using the mcoqe external registry. The credentials to pull and push images in the mcoqe repo should be previously added to the cluster's pull secret
171
- func CreateMachineOSConfigUsingExternalRegistry (oc * exutil.CLI , name , pool string , containerFile []ContainerFile , defaultPullSecret bool ) (* MachineOSConfig , error ) {
171
+ func CreateMachineOSConfigUsingExternalRegistry (oc * exutil.CLI , moscAndMcpName string , containerFile []ContainerFile , defaultPullSecret bool ) (* MachineOSConfig , error ) {
172
172
var (
173
173
// We use a copy of the cluster's pull secret to pull the images
174
174
pullSecret = NewSecret (oc .AsAdmin (), "openshift-config" , "pull-secret" )
175
175
)
176
176
copyPullSecret , err := CopySecretToMCONamespace (pullSecret , "cloned-pull-secret-" + exutil .GetRandomString ())
177
177
if err != nil {
178
- return NewMachineOSConfig (oc , name ), err
178
+ return NewMachineOSConfig (oc , moscAndMcpName ), err
179
179
}
180
180
181
181
clusterName , err := exutil .GetInfraID (oc )
182
182
if err != nil {
183
- return NewMachineOSConfig (oc , name ), err
183
+ return NewMachineOSConfig (oc , moscAndMcpName ), err
184
184
}
185
185
186
186
// We use a push spec stored in the internal registry in the MCO namespace. We use a different image for every pool
187
- pushSpec := fmt .Sprintf ("%s:ocb-%s-%s" , DefaultLayeringQuayRepository , pool , clusterName )
187
+ pushSpec := fmt .Sprintf ("%s:ocb-%s-%s" , DefaultLayeringQuayRepository , moscAndMcpName , clusterName )
188
188
189
189
// If we use the external registry we need to add an expiration date label so that the images are automatically cleaned
190
190
configuredContainerFile := []ContainerFile {}
@@ -197,25 +197,25 @@ func CreateMachineOSConfigUsingExternalRegistry(oc *exutil.CLI, name, pool strin
197
197
}
198
198
199
199
if defaultPullSecret {
200
- return CreateMachineOSConfigWithDefaultBasImagePullSecret (oc , name , pool , copyPullSecret .GetName (), pushSpec , configuredContainerFile )
200
+ return CreateMachineOSConfigWithDefaultBasImagePullSecret (oc , moscAndMcpName , copyPullSecret .GetName (), pushSpec , configuredContainerFile )
201
201
}
202
202
203
- return CreateMachineOSConfig (oc , name , pool , copyPullSecret .GetName (), copyPullSecret .GetName (), pushSpec , configuredContainerFile )
203
+ return CreateMachineOSConfig (oc , moscAndMcpName , copyPullSecret .GetName (), copyPullSecret .GetName (), pushSpec , configuredContainerFile )
204
204
205
205
}
206
206
207
207
// CreateMachineOSConfigUsingExternalOrInternalRegistry creates a MOSC using internal registry if possible, if not possible it will use external registry. It will define the BaseImagePullSecret too
208
- func CreateMachineOSConfigUsingExternalOrInternalRegistry (oc * exutil.CLI , namespace , name , pool string , containerFile []ContainerFile ) (* MachineOSConfig , error ) {
209
- return createMachineOSConfigUsingExternalOrInternalRegistry (oc , namespace , name , pool , containerFile , false )
208
+ func CreateMachineOSConfigUsingExternalOrInternalRegistry (oc * exutil.CLI , namespace , moscAndMcpName string , containerFile []ContainerFile ) (* MachineOSConfig , error ) {
209
+ return createMachineOSConfigUsingExternalOrInternalRegistry (oc , namespace , moscAndMcpName , containerFile , false )
210
210
}
211
211
212
212
// createMachineOSConfigUsingExternalOrInternalRegistry creates a MOSC using internal registry if possible, if not possible it will use external registry
213
- func createMachineOSConfigUsingExternalOrInternalRegistry (oc * exutil.CLI , namespace , name , pool string , containerFile []ContainerFile , defaultPullSecret bool ) (* MachineOSConfig , error ) {
213
+ func createMachineOSConfigUsingExternalOrInternalRegistry (oc * exutil.CLI , namespace , moscAndMcpName string , containerFile []ContainerFile , defaultPullSecret bool ) (* MachineOSConfig , error ) {
214
214
if CanUseInternalRegistryToStoreOSImage (oc ) {
215
- return CreateMachineOSConfigUsingInternalRegistry (oc , namespace , name , pool , containerFile , defaultPullSecret )
215
+ return CreateMachineOSConfigUsingInternalRegistry (oc , namespace , moscAndMcpName , containerFile , defaultPullSecret )
216
216
}
217
217
218
- return CreateMachineOSConfigUsingExternalRegistry (oc , name , pool , containerFile , defaultPullSecret )
218
+ return CreateMachineOSConfigUsingExternalRegistry (oc , moscAndMcpName , containerFile , defaultPullSecret )
219
219
220
220
}
221
221
0 commit comments