Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCPBUGS-31919: Use proper pull-secret for getting openshift-tests image #28764

Merged
merged 3 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func updateDeploymentENVs(deployment *appsv1.Deployment, deploymentID, serviceCl
func (pna *podNetworkAvalibility) StartCollection(ctx context.Context, adminRESTConfig *rest.Config, recorder monitorapi.RecorderWriter) error {
deploymentID := uuid.New().String()

openshiftTestsImagePullSpec, err := GetOpenshiftTestsImagePullSpec(ctx, adminRESTConfig, pna.payloadImagePullSpec)
openshiftTestsImagePullSpec, err := GetOpenshiftTestsImagePullSpec(ctx, adminRESTConfig, pna.payloadImagePullSpec, nil)
if err != nil {
pna.notSupportedReason = &monitortestframework.NotSupportedError{Reason: fmt.Sprintf("unable to determine openshift-tests image: %v", err)}
return pna.notSupportedReason
Expand Down
64 changes: 61 additions & 3 deletions pkg/monitortests/network/disruptionpodnetwork/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ import (
"bytes"
"context"
"fmt"
"github.com/sirupsen/logrus"
"io/ioutil"
"os"
"os/exec"
"strings"

configclient "github.com/openshift/client-go/config/clientset/versioned"
exutil "github.com/openshift/origin/test/extended/util"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/rest"
)

// GetOpenshiftTestsImagePullSpec returns the pull spec or an error.
func GetOpenshiftTestsImagePullSpec(ctx context.Context, adminRESTConfig *rest.Config, suggestedPayloadImage string) (string, error) {
// IN ginkgo environment, oc needs to be created before BeforeEach and passed in
func GetOpenshiftTestsImagePullSpec(ctx context.Context, adminRESTConfig *rest.Config, suggestedPayloadImage string, oc *exutil.CLI) (string, error) {
if len(suggestedPayloadImage) == 0 {
configClient, err := configclient.NewForConfig(adminRESTConfig)
if err != nil {
Expand All @@ -30,16 +35,69 @@ func GetOpenshiftTestsImagePullSpec(ctx context.Context, adminRESTConfig *rest.C
suggestedPayloadImage = clusterVersion.Status.History[0].Image
}

logrus.Infof("payload image reported by CV: %v\n", suggestedPayloadImage)
// runImageExtract extracts src from specified image to dst
cmd := exec.Command("oc", "adm", "release", "info", suggestedPayloadImage, "--image-for=tests")
out := &bytes.Buffer{}
outStr := ""
errOut := &bytes.Buffer{}
cmd.Stdout = out
cmd.Stderr = errOut
if err := cmd.Run(); err != nil {
return "", fmt.Errorf("unable to determine openshift-tests image: %v: %v", err, errOut.String())
logrus.WithError(err).Errorf("unable to determine openshift-tests image through exec: %v", errOut.String())
// Now try the wrapper to see if it makes a difference
if oc == nil {
oc = exutil.NewCLIWithoutNamespace("openshift-tests")
}
outStr, err = oc.Run("adm", "release", "info", suggestedPayloadImage).Args("--image-for=tests").Output()
if err != nil {
logrus.WithError(err).Errorf("unable to determine openshift-tests image through oc wrapper with default ps: %v", outStr)

kubeClient := oc.AdminKubeClient()
// Try to use the same pull secret as the cluster under test
imagePullSecret, err := kubeClient.CoreV1().Secrets("openshift-config").Get(context.Background(), "pull-secret", metav1.GetOptions{})
if err != nil {
logrus.WithError(err).Errorf("unable to get pull secret from cluster: %v", err)
return "", fmt.Errorf("unable to get pull secret from cluster: %v", err)
}

// cache file to local temp location
imagePullFile, err := ioutil.TempFile("", "image-pull-secret")
if err != nil {
logrus.WithError(err).Errorf("unable to create a temporary file: %v", err)
return "", fmt.Errorf("unable to create a temporary file: %v", err)
}
defer os.Remove(imagePullFile.Name())

// write the content
imagePullSecretBytes := imagePullSecret.Data[".dockerconfigjson"]
if _, err = imagePullFile.Write(imagePullSecretBytes); err != nil {
logrus.WithError(err).Errorf("unable to write pull secret to temp file: %v", err)
return "", fmt.Errorf("unable to write pull secret to temp file: %v", err)
}
if err = imagePullFile.Close(); err != nil {
logrus.WithError(err).Errorf("unable to close file: %v", err)
return "", fmt.Errorf("unable to close file: %v", err)
}

outStr, err = oc.Run("adm", "release", "info", suggestedPayloadImage).Args("--image-for=tests", "--registry-config", imagePullFile.Name()).Output()
if err != nil {
logrus.WithError(err).Errorf("unable to determine openshift-tests image through oc wrapper with cluster ps")

// What is the mirror mode

return "", fmt.Errorf("unable to determine openshift-tests image oc wrapper with cluster ps: %v", err)
} else {
logrus.Infof("successfully getting image for test with oc wrapper with cluster ps: %s\n", outStr)
}
} else {
logrus.Infof("successfully getting image for test with oc wrapper with default ps: %s\n", outStr)
}
} else {
outStr = out.String()
}
openshiftTestsImagePullSpec := strings.TrimSpace(out.String())

openshiftTestsImagePullSpec := strings.TrimSpace(outStr)
fmt.Printf("openshift-tests image pull spec is %v\n", openshiftTestsImagePullSpec)

return openshiftTestsImagePullSpec, nil
Expand Down
2 changes: 1 addition & 1 deletion test/extended/operators/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ var _ = g.Describe(fmt.Sprintf("[sig-arch][Late][Jira:%q]", "kube-apiserver"), g
inClusterPKIContent, err := gatherCertsFromPlatformNamespaces(ctx, kubeClient, masters)
o.Expect(err).NotTo(o.HaveOccurred())

openshiftTestImagePullSpec, err := disruptionpodnetwork.GetOpenshiftTestsImagePullSpec(ctx, oc.AdminConfig(), "")
openshiftTestImagePullSpec, err := disruptionpodnetwork.GetOpenshiftTestsImagePullSpec(ctx, oc.AdminConfig(), "", oc)
// Skip metal jobs if test image pullspec cannot be determined
if jobType.Platform != "metal" || err == nil {
o.Expect(err).NotTo(o.HaveOccurred())
Expand Down