Skip to content

Commit 4fbbf9b

Browse files
Merge pull request #5249 from isabella-janssen/mosc-test-names
OCPBUGS-60559: Update the OnClusterBuild payload tests to reflect the validation rule requiring MCP & MOSC names to match
2 parents 03a3677 + ddc2cdb commit 4fbbf9b

File tree

2 files changed

+59
-64
lines changed

2 files changed

+59
-64
lines changed

test/extended/machineosconfig.go

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,31 @@ func NewMachineOSConfigList(oc *exutil.CLI) *MachineOSConfigList {
3939
}
4040

4141
// 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)
4444
}
4545

4646
// 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)
4949
}
5050

5151
// 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) {
5353
var (
5454
containerFilesString = "[]"
5555
moscTemplateFile = "generic-machine-os-config-nobaseimagepull.yaml"
56-
parameters = []string{"-p", "NAME=" + name, "POOL=" + pool,
56+
parameters = []string{"-p", "NAME=" + moscAndMcpName, "POOL=" + moscAndMcpName,
5757
"RENDEREDIMAGEPUSHSECRET=" + renderedImagePushSecret, "PUSHSPEC=" + pushSpec}
5858
)
5959
if baseImagePullSecret != nil {
6060
moscTemplateFile = "generic-machine-os-config.yaml"
6161
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)
6363
} 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)
6565
}
66-
newMOSC := NewMachineOSConfig(oc, name)
66+
newMOSC := NewMachineOSConfig(oc, moscAndMcpName)
6767

6868
if len(containerFile) > 0 {
6969
containerFilesBytes, err := json.Marshal(containerFile)
@@ -103,15 +103,15 @@ func CopySecretToMCONamespace(secret *Secret, newName string) (*Secret, error) {
103103
return &Secret{Resource: *mcoResource}, nil
104104
}
105105

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) {
107107

108108
// We use the builder SA secret in the namespace to push the images to the internal registry
109109
renderedImagePushSecret, err := CreateInternalRegistrySecretFromSA(oc, "builder", namespace, "cloned-push-secret"+exutil.GetRandomString(), MachineConfigNamespace)
110110
if err != nil {
111-
return NewMachineOSConfig(oc, name), err
111+
return NewMachineOSConfig(oc, moscAndMcpName), err
112112
}
113113
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)
115115
}
116116

117117
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,
120120
// We use the default SA secret in MCO to pull the current image from the internal registry
121121
namespacedPullSecret, err := CreateInternalRegistrySecretFromSA(oc, "default", namespace, "cloned-currentpull-secret"+exutil.GetRandomString(), namespace)
122122
if err != nil {
123-
return NewMachineOSConfig(oc, name), err
123+
return NewMachineOSConfig(oc, moscAndMcpName), err
124124
}
125125
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)
127127
}
128128

129129
namespacedDockerConfig, err := namespacedPullSecret.GetDataValue(".dockerconfigjson")
130130
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")
132132
}
133133

134134
pullSecret := GetPullSecret(oc.AsAdmin())
135135
pullSecretDockerConfig, err := pullSecret.GetDataValue(".dockerconfigjson")
136136
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")
138138
}
139139

140140
mergedDockerConfig, err := MergeDockerConfigs(pullSecretDockerConfig, namespacedDockerConfig)
141141
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")
143143
}
144144

145145
err = pullSecret.SetDataValue(".dockerconfigjson", mergedDockerConfig)
146146
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")
148148
}
149149

150150
logger.Infof("Waiting for the secret to be updated in all pools")
151151
NewMachineConfigPoolList(oc.AsAdmin()).waitForComplete()
152152
}
153153

154154
// 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)
156156

157157
if !defaultPullSecret {
158158
// We use a copy of the cluster's pull secret to pull the images
159159
pullSecret := NewSecret(oc.AsAdmin(), "openshift-config", "pull-secret")
160160
baseImagePullSecret, err := CopySecretToMCONamespace(pullSecret, "cloned-basepull-secret-"+exutil.GetRandomString())
161161
if err != nil {
162-
return NewMachineOSConfig(oc, name), err
162+
return NewMachineOSConfig(oc, moscAndMcpName), err
163163
}
164-
return CreateMachineOSConfig(oc, name, pool, baseImagePullSecret.GetName(), renderedImagePushSecret.GetName(), pushSpec, containerFile)
164+
return CreateMachineOSConfig(oc, moscAndMcpName, baseImagePullSecret.GetName(), renderedImagePushSecret.GetName(), pushSpec, containerFile)
165165
}
166166

167-
return CreateMachineOSConfigWithDefaultBasImagePullSecret(oc, name, pool, renderedImagePushSecret.GetName(), pushSpec, containerFile)
167+
return CreateMachineOSConfigWithDefaultBasImagePullSecret(oc, moscAndMcpName, renderedImagePushSecret.GetName(), pushSpec, containerFile)
168168
}
169169

170170
// 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) {
172172
var (
173173
// We use a copy of the cluster's pull secret to pull the images
174174
pullSecret = NewSecret(oc.AsAdmin(), "openshift-config", "pull-secret")
175175
)
176176
copyPullSecret, err := CopySecretToMCONamespace(pullSecret, "cloned-pull-secret-"+exutil.GetRandomString())
177177
if err != nil {
178-
return NewMachineOSConfig(oc, name), err
178+
return NewMachineOSConfig(oc, moscAndMcpName), err
179179
}
180180

181181
clusterName, err := exutil.GetInfraID(oc)
182182
if err != nil {
183-
return NewMachineOSConfig(oc, name), err
183+
return NewMachineOSConfig(oc, moscAndMcpName), err
184184
}
185185

186186
// 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)
188188

189189
// If we use the external registry we need to add an expiration date label so that the images are automatically cleaned
190190
configuredContainerFile := []ContainerFile{}
@@ -197,25 +197,25 @@ func CreateMachineOSConfigUsingExternalRegistry(oc *exutil.CLI, name, pool strin
197197
}
198198

199199
if defaultPullSecret {
200-
return CreateMachineOSConfigWithDefaultBasImagePullSecret(oc, name, pool, copyPullSecret.GetName(), pushSpec, configuredContainerFile)
200+
return CreateMachineOSConfigWithDefaultBasImagePullSecret(oc, moscAndMcpName, copyPullSecret.GetName(), pushSpec, configuredContainerFile)
201201
}
202202

203-
return CreateMachineOSConfig(oc, name, pool, copyPullSecret.GetName(), copyPullSecret.GetName(), pushSpec, configuredContainerFile)
203+
return CreateMachineOSConfig(oc, moscAndMcpName, copyPullSecret.GetName(), copyPullSecret.GetName(), pushSpec, configuredContainerFile)
204204

205205
}
206206

207207
// 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)
210210
}
211211

212212
// 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) {
214214
if CanUseInternalRegistryToStoreOSImage(oc) {
215-
return CreateMachineOSConfigUsingInternalRegistry(oc, namespace, name, pool, containerFile, defaultPullSecret)
215+
return CreateMachineOSConfigUsingInternalRegistry(oc, namespace, moscAndMcpName, containerFile, defaultPullSecret)
216216
}
217217

218-
return CreateMachineOSConfigUsingExternalRegistry(oc, name, pool, containerFile, defaultPullSecret)
218+
return CreateMachineOSConfigUsingExternalRegistry(oc, moscAndMcpName, containerFile, defaultPullSecret)
219219

220220
}
221221

0 commit comments

Comments
 (0)