Skip to content

Commit 367e218

Browse files
authored
fix: change auth option (konflux-ci#1727)
1 parent 6988924 commit 367e218

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

tests/build/build_templates.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,7 @@ func enableHermeticBuildInPipelineBundle(customDockerBuildBundle string, pipelin
820820
var tektonObj runtime.Object
821821
var err error
822822
var newPipelineYaml []byte
823+
var authenticator authn.Authenticator
823824
// Extract docker-build pipeline as tekton object from the bundle
824825
if tektonObj, err = tekton.ExtractTektonObjectFromBundle(customDockerBuildBundle, "pipeline", pipelineBundleName); err != nil {
825826
return "", fmt.Errorf("failed to extract the Tekton Pipeline from bundle: %+v", err)
@@ -837,13 +838,16 @@ func enableHermeticBuildInPipelineBundle(customDockerBuildBundle string, pipelin
837838
if newPipelineYaml, err = yaml.Marshal(dockerPipelineObject); err != nil {
838839
return "", fmt.Errorf("error when marshalling a new pipeline to YAML: %v", err)
839840
}
840-
keychain := authn.NewMultiKeychain(authn.DefaultKeychain)
841-
authOption := remoteimg.WithAuthFromKeychain(keychain)
841+
842842
tag := fmt.Sprintf("%d-%s", time.Now().Unix(), util.GenerateRandomString(4))
843843
quayOrg := utils.GetEnv(constants.QUAY_E2E_ORGANIZATION_ENV, constants.DefaultQuayOrg)
844844
newDockerBuildPipelineImg := strings.ReplaceAll(constants.DefaultImagePushRepo, constants.DefaultQuayOrg, quayOrg)
845845
var newDockerBuildPipeline, _ = name.ParseReference(fmt.Sprintf("%s:pipeline-bundle-%s", newDockerBuildPipelineImg, tag))
846846
// Build and Push the tekton bundle
847+
if authenticator, err = utils.GetAuthenticatorForImageRef(newDockerBuildPipeline, os.Getenv("QUAY_TOKEN")); err != nil {
848+
return "", fmt.Errorf("error when getting authenticator: %v", err)
849+
}
850+
authOption := remoteimg.WithAuth(authenticator)
847851
if err = tekton.BuildAndPushTektonBundle(newPipelineYaml, newDockerBuildPipeline, authOption); err != nil {
848852
return "", fmt.Errorf("error when building/pushing a tekton pipeline bundle: %v", err)
849853
}
@@ -856,6 +860,7 @@ func enableDockerMediaTypeInPipelineBundle(customDockerBuildBundle string, pipel
856860
var tektonObj runtime.Object
857861
var err error
858862
var newPipelineYaml []byte
863+
var authenticator authn.Authenticator
859864
// Extract docker-build pipeline as tekton object from the bundle
860865
if tektonObj, err = tekton.ExtractTektonObjectFromBundle(customDockerBuildBundle, "pipeline", pipelineBundleName); err != nil {
861866
return "", fmt.Errorf("failed to extract the Tekton Pipeline from bundle: %+v", err)
@@ -883,13 +888,16 @@ func enableDockerMediaTypeInPipelineBundle(customDockerBuildBundle string, pipel
883888
if newPipelineYaml, err = yaml.Marshal(dockerPipelineObject); err != nil {
884889
return "", fmt.Errorf("error when marshalling a new pipeline to YAML: %v", err)
885890
}
886-
keychain := authn.NewMultiKeychain(authn.DefaultKeychain)
887-
authOption := remoteimg.WithAuthFromKeychain(keychain)
891+
888892
tag := fmt.Sprintf("%d-%s", time.Now().Unix(), util.GenerateRandomString(4))
889893
quayOrg := utils.GetEnv(constants.QUAY_E2E_ORGANIZATION_ENV, constants.DefaultQuayOrg)
890894
newDockerBuildPipelineImg := strings.ReplaceAll(constants.DefaultImagePushRepo, constants.DefaultQuayOrg, quayOrg)
891895
var newDockerBuildPipeline, _ = name.ParseReference(fmt.Sprintf("%s:pipeline-bundle-%s", newDockerBuildPipelineImg, tag))
892896
// Build and Push the tekton bundle
897+
if authenticator, err = utils.GetAuthenticatorForImageRef(newDockerBuildPipeline, os.Getenv("QUAY_TOKEN")); err != nil {
898+
return "", fmt.Errorf("error when getting authenticator: %v", err)
899+
}
900+
authOption := remoteimg.WithAuth(authenticator)
893901
if err = tekton.BuildAndPushTektonBundle(newPipelineYaml, newDockerBuildPipeline, authOption); err != nil {
894902
return "", fmt.Errorf("error when building/pushing a tekton pipeline bundle: %v", err)
895903
}
@@ -904,6 +912,7 @@ func applyAdditionalTagsInPipelineBundle(customDockerBuildBundle string, pipelin
904912
var tektonObj runtime.Object
905913
var err error
906914
var newPipelineYaml []byte
915+
var authenticator authn.Authenticator
907916
// Extract docker-build pipeline as tekton object from the bundle
908917
if tektonObj, err = tekton.ExtractTektonObjectFromBundle(customDockerBuildBundle, "pipeline", pipelineBundleName); err != nil {
909918
return "", fmt.Errorf("failed to extract the Tekton Pipeline from bundle: %+v", err)
@@ -920,13 +929,16 @@ func applyAdditionalTagsInPipelineBundle(customDockerBuildBundle string, pipelin
920929
if newPipelineYaml, err = yaml.Marshal(dockerPipelineObject); err != nil {
921930
return "", fmt.Errorf("error when marshalling a new pipeline to YAML: %v", err)
922931
}
923-
keychain := authn.NewMultiKeychain(authn.DefaultKeychain)
924-
authOption := remoteimg.WithAuthFromKeychain(keychain)
932+
925933
tag := fmt.Sprintf("%d-%s", time.Now().Unix(), util.GenerateRandomString(4))
926934
quayOrg := utils.GetEnv(constants.QUAY_E2E_ORGANIZATION_ENV, constants.DefaultQuayOrg)
927935
newDockerBuildPipelineImg := strings.ReplaceAll(constants.DefaultImagePushRepo, constants.DefaultQuayOrg, quayOrg)
928936
var newDockerBuildPipeline, _ = name.ParseReference(fmt.Sprintf("%s:pipeline-bundle-%s", newDockerBuildPipelineImg, tag))
929937
// Build and Push the tekton bundle
938+
if authenticator, err = utils.GetAuthenticatorForImageRef(newDockerBuildPipeline, os.Getenv("QUAY_TOKEN")); err != nil {
939+
return "", fmt.Errorf("error when getting authenticator: %v", err)
940+
}
941+
authOption := remoteimg.WithAuth(authenticator)
930942
if err = tekton.BuildAndPushTektonBundle(newPipelineYaml, newDockerBuildPipeline, authOption); err != nil {
931943
return "", fmt.Errorf("error when building/pushing a tekton pipeline bundle: %v", err)
932944
}
@@ -940,6 +952,7 @@ func addWorkingDirMountInPipelineBundle(customDockerBuildBundle string, pipeline
940952
var tektonObj runtime.Object
941953
var err error
942954
var newPipelineYaml []byte
955+
var authenticator authn.Authenticator
943956
// Extract docker-build pipeline as tekton object from the bundle
944957
if tektonObj, err = tekton.ExtractTektonObjectFromBundle(customDockerBuildBundle, "pipeline", pipelineBundleName); err != nil {
945958
return "", fmt.Errorf("failed to extract the Tekton Pipeline from bundle: %+v", err)
@@ -958,13 +971,16 @@ func addWorkingDirMountInPipelineBundle(customDockerBuildBundle string, pipeline
958971
if newPipelineYaml, err = yaml.Marshal(dockerPipelineObject); err != nil {
959972
return "", fmt.Errorf("error when marshalling a new pipeline to YAML: %v", err)
960973
}
961-
keychain := authn.NewMultiKeychain(authn.DefaultKeychain)
962-
authOption := remoteimg.WithAuthFromKeychain(keychain)
974+
963975
tag := fmt.Sprintf("%d-%s", time.Now().Unix(), util.GenerateRandomString(4))
964976
quayOrg := utils.GetEnv(constants.QUAY_E2E_ORGANIZATION_ENV, constants.DefaultQuayOrg)
965977
newDockerBuildPipelineImg := strings.ReplaceAll(constants.DefaultImagePushRepo, constants.DefaultQuayOrg, quayOrg)
966978
var newDockerBuildPipeline, _ = name.ParseReference(fmt.Sprintf("%s:pipeline-bundle-%s", newDockerBuildPipelineImg, tag))
967979
// Build and Push the tekton bundle
980+
if authenticator, err = utils.GetAuthenticatorForImageRef(newDockerBuildPipeline, os.Getenv("QUAY_TOKEN")); err != nil {
981+
return "", fmt.Errorf("error when getting authenticator: %v", err)
982+
}
983+
authOption := remoteimg.WithAuth(authenticator)
968984
if err = tekton.BuildAndPushTektonBundle(newPipelineYaml, newDockerBuildPipeline, authOption); err != nil {
969985
return "", fmt.Errorf("error when building/pushing a tekton pipeline bundle: %v", err)
970986
}

0 commit comments

Comments
 (0)