Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/cli/admin/verifyimagesignature/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"net/url"

"github.com/docker/distribution/registry/client/transport"
godigest "github.com/opencontainers/go-digest"

"k8s.io/client-go/rest"
Expand All @@ -27,6 +28,7 @@ func getImageManifestByIDFromRegistry(registry *url.URL, repositoryName, imageID

repo, err := registryclient.NewContext(http.DefaultTransport, insecureRT).
WithCredentials(credentials).
WithRequestModifiers(transport.NewHeaderRequestModifier(http.Header{http.CanonicalHeaderKey("User-Agent"): []string{rest.DefaultKubernetesUserAgent()}})).
Repository(ctx, registry, repositoryName, insecure)
if err != nil {
return nil, err
Expand Down
4 changes: 3 additions & 1 deletion pkg/cli/image/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/docker/distribution/reference"
"github.com/docker/distribution/registry/api/errcode"
v2 "github.com/docker/distribution/registry/api/v2"
"github.com/docker/distribution/registry/client/transport"

"github.com/docker/libtrust"
"github.com/opencontainers/go-digest"
Expand Down Expand Up @@ -129,7 +130,8 @@ func (o *SecurityOptions) NewContext() (*registryclient.Context, error) {
return nil, fmt.Errorf("unable to load --registry-config: %v", err)
}
}
context := registryclient.NewContext(rt, insecureRT).WithCredentials(creds)
context := registryclient.NewContext(rt, insecureRT).WithCredentials(creds).
WithRequestModifiers(transport.NewHeaderRequestModifier(http.Header{http.CanonicalHeaderKey("User-Agent"): []string{rest.DefaultKubernetesUserAgent()}}))
context.DisableDigestVerification = o.SkipVerification
return context, nil
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/cli/registry/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import (
"net/http"
"net/url"

"github.com/docker/distribution/registry/client/transport"
"github.com/spf13/cobra"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/rest"
kcmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/templates"

Expand Down Expand Up @@ -184,7 +186,8 @@ func (o *Options) Run() error {
fmt.Fprintf(o.ErrOut, "info: Registry does not have a public hostname\n")
}
url := &url.URL{Host: host}
c := registryclient.NewContext(http.DefaultTransport, http.DefaultTransport)
c := registryclient.NewContext(http.DefaultTransport, http.DefaultTransport).
WithRequestModifiers(transport.NewHeaderRequestModifier(http.Header{http.CanonicalHeaderKey("User-Agent"): []string{rest.DefaultKubernetesUserAgent()}}))
_, src, err := c.Ping(ctx, url, false)
if err != nil {
return fmt.Errorf("registry could not be contacted at %s: %v", url.Host, err)
Expand Down
8 changes: 5 additions & 3 deletions pkg/cli/registry/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,24 @@ import (
"path/filepath"
"strings"

"github.com/docker/distribution/registry/client/transport"
"github.com/spf13/cobra"
"k8s.io/klog/v2"

corev1 "k8s.io/api/core/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/cli-runtime/pkg/genericclioptions"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/util/homedir"
"k8s.io/klog/v2"
kcmdutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/templates"

imageclient "github.com/openshift/client-go/image/clientset/versioned"
"github.com/openshift/library-go/pkg/image/reference"
"github.com/openshift/library-go/pkg/image/registryclient"
"k8s.io/cli-runtime/pkg/genericclioptions"
)

var (
Expand Down Expand Up @@ -284,7 +285,8 @@ func (o *LoginOptions) Run() error {
if err != nil {
return err
}
c := registryclient.NewContext(http.DefaultTransport, insecureRT).WithCredentials(creds)
c := registryclient.NewContext(http.DefaultTransport, insecureRT).WithCredentials(creds).
WithRequestModifiers(transport.NewHeaderRequestModifier(http.Header{http.CanonicalHeaderKey("User-Agent"): []string{rest.DefaultKubernetesUserAgent()}}))
if _, err := c.Repository(ctx, url, "does_not_exist", o.Insecure); err != nil {
return fmt.Errorf("unable to check your credentials - pass --skip-check to bypass this error: %v", err)
}
Expand Down
56 changes: 28 additions & 28 deletions pkg/helpers/newapp/newapptest/newapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ func TestNewAppRunAll(t *testing.T) {
Resolvers: cmd.Resolvers{
DockerSearcher: app.DockerClientSearcher{
Client: &apptest.FakeDockerClient{
Images: []docker.APIImages{{RepoTags: []string{"centos/ruby-27-centos7"}}},
Images: []docker.APIImages{{RepoTags: []string{"quay.io/centos7/ruby-27-centos7"}}},
Image: dockerBuilderImage(),
},
Insecure: true,
Expand Down Expand Up @@ -1075,7 +1075,7 @@ func TestNewAppRunBuilds(t *testing.T) {
config: &cmd.AppConfig{
ComponentInputs: cmd.ComponentInputs{
SourceRepositories: []string{"https://github.com/openshift/ruby-hello-world"},
DockerImages: []string{"centos/ruby-27-centos7", "openshift/nodejs-010-centos7"},
DockerImages: []string{"quay.io/centos7/ruby-27-centos7", "openshift/nodejs-010-centos7"},
},
GenerationInputs: cmd.GenerationInputs{
OutputDocker: true,
Expand Down Expand Up @@ -1181,7 +1181,7 @@ func TestNewAppRunBuilds(t *testing.T) {
SourceRepositories: []string{"https://github.com/openshift/ruby-hello-world"},
},
GenerationInputs: cmd.GenerationInputs{
Dockerfile: "FROM centos/ruby-27-centos7\nRUN false",
Dockerfile: "FROM quay.io/centos7/ruby-27-centos7\nRUN false",
},
},
expected: map[string][]string{
Expand All @@ -1206,7 +1206,7 @@ func TestNewAppRunBuilds(t *testing.T) {
if bc.Spec.Source.Dockerfile != nil {
got = *bc.Spec.Source.Dockerfile
}
want := "FROM centos/ruby-27-centos7\nRUN false"
want := "FROM quay.io/centos7/ruby-27-centos7\nRUN false"
if got != want {
return fmt.Errorf("bc.Spec.Source.Dockerfile = %q; want %q", got, want)
}
Expand Down Expand Up @@ -1247,7 +1247,7 @@ func TestNewAppRunBuilds(t *testing.T) {
},
},
GenerationInputs: cmd.GenerationInputs{
Dockerfile: "FROM centos/ruby-27-centos7\nRUN false",
Dockerfile: "FROM quay.io/centos7/ruby-27-centos7\nRUN false",
},
},
expectedErr: func(err error) bool {
Expand All @@ -1263,13 +1263,13 @@ func TestNewAppRunBuilds(t *testing.T) {
},
},
GenerationInputs: cmd.GenerationInputs{
SourceImage: "centos/mongodb-26-centos7",
SourceImage: "registry.centos.org/centos/mongodb-34-centos7",
SourceImagePath: "/src:dst",
},
},
expected: map[string][]string{
"buildConfig": {"ruby-hello-world"},
"imageStream": {"mongodb-26-centos7", "ruby-27-centos7", "ruby-hello-world"},
"imageStream": {"mongodb-34-centos7", "ruby-27-centos7", "ruby-hello-world"},
},
checkResult: func(res *cmd.AppResult) error {
var bc *buildv1.BuildConfig
Expand All @@ -1287,7 +1287,7 @@ func TestNewAppRunBuilds(t *testing.T) {
}
var got string

want := "mongodb-26-centos7:latest"
want := "mongodb-34-centos7:latest"
got = bc.Spec.Source.Images[0].From.Name
if got != want {
return fmt.Errorf("bc.Spec.Source.Image.From.Name = %q; want %q", got, want)
Expand Down Expand Up @@ -1321,13 +1321,13 @@ func TestNewAppRunBuilds(t *testing.T) {
},
GenerationInputs: cmd.GenerationInputs{
To: "outputimage",
SourceImage: "centos/mongodb-26-centos7",
SourceImage: "registry.centos.org/centos/mongodb-34-centos7",
SourceImagePath: "/src:dst",
},
},
expected: map[string][]string{
"buildConfig": {"outputimage"},
"imageStream": {"mongodb-26-centos7", "nodejs-010-centos7", "outputimage"},
"imageStream": {"mongodb-34-centos7", "nodejs-010-centos7", "outputimage"},
},
checkResult: func(res *cmd.AppResult) error {
var bc *buildv1.BuildConfig
Expand All @@ -1345,7 +1345,7 @@ func TestNewAppRunBuilds(t *testing.T) {
}
var got string

want := "mongodb-26-centos7:latest"
want := "mongodb-34-centos7:latest"
got = bc.Spec.Source.Images[0].From.Name
if got != want {
return fmt.Errorf("bc.Spec.Source.Image.From.Name = %q; want %q", got, want)
Expand Down Expand Up @@ -1420,7 +1420,7 @@ func TestNewAppRunBuilds(t *testing.T) {
config: &cmd.AppConfig{
ComponentInputs: cmd.ComponentInputs{
Components: []string{
"centos/nodejs-4-centos7~https://github.com/sclorg/nodejs-ex",
"registry.centos.org/centos/nodejs-12-centos7~https://github.com/sclorg/nodejs-ex",
},
},
GenerationInputs: cmd.GenerationInputs{
Expand Down Expand Up @@ -1582,8 +1582,8 @@ func TestNewAppBuildOutputCycleDetection(t *testing.T) {
config: &cmd.AppConfig{
GenerationInputs: cmd.GenerationInputs{
OutputDocker: true,
To: "centos/ruby-27-centos7",
Dockerfile: "FROM centos/ruby-27-centos7:latest",
To: "quay.io/centos7/ruby-27-centos7",
Dockerfile: "FROM quay.io/centos7/ruby-27-centos7:latest",
},
},
expected: map[string][]string{
Expand All @@ -1595,7 +1595,7 @@ func TestNewAppBuildOutputCycleDetection(t *testing.T) {
if err != nil {
return err
}
want := "--> WARNING: output image of \"centos/ruby-27-centos7:latest\" should be different than input\n"
want := "--> WARNING: output image of \"quay.io/centos7/ruby-27-centos7:latest\" should be different than input\n"
if string(got) != want {
return fmt.Errorf("stderr: got %q; want %q", got, want)
}
Expand Down Expand Up @@ -1630,7 +1630,7 @@ func TestNewAppBuildOutputCycleDetection(t *testing.T) {
name: "successful build from dockerfile with identical input and output image references with warning(2)",
config: &cmd.AppConfig{
GenerationInputs: cmd.GenerationInputs{
Dockerfile: "FROM centos/ruby-27-centos7\nRUN yum install -y httpd",
Dockerfile: "FROM quay.io/centos7/ruby-27-centos7\nRUN yum install -y httpd",
To: "ruby-27-centos7",
},
},
Expand All @@ -1643,7 +1643,7 @@ func TestNewAppBuildOutputCycleDetection(t *testing.T) {
if err != nil {
return err
}
want := "--> WARNING: output image of \"centos/ruby-27-centos7:latest\" should be different than input\n"
want := "--> WARNING: output image of \"quay.io/centos7/ruby-27-centos7:latest\" should be different than input\n"
if string(got) != want {
return fmt.Errorf("stderr: got %q; want %q", got, want)
}
Expand All @@ -1668,12 +1668,12 @@ func TestNewAppBuildOutputCycleDetection(t *testing.T) {
name: "unsuccessful build from dockerfile due to identical input and output image references(2)",
config: &cmd.AppConfig{
GenerationInputs: cmd.GenerationInputs{
Dockerfile: "FROM centos/ruby-27-centos7\nRUN yum install -y httpd",
Dockerfile: "FROM quay.io/centos7/ruby-27-centos7\nRUN yum install -y httpd",
},
},
expectedErr: func(err error) bool {
e := app.CircularOutputReferenceError{
Reference: "centos/ruby-27-centos7:latest",
Reference: "quay.io/centos7/ruby-27-centos7:latest",
}
return err.Error() == fmt.Errorf("%v, set a different tag with --to", e).Error()
},
Expand All @@ -1683,8 +1683,8 @@ func TestNewAppBuildOutputCycleDetection(t *testing.T) {
config: &cmd.AppConfig{
GenerationInputs: cmd.GenerationInputs{
OutputDocker: true,
To: "centos/ruby-27-centos7",
Dockerfile: "FROM centos/ruby-27-centos7",
To: "quay.io/centos7/ruby-27-centos7",
Dockerfile: "FROM quay.io/centos7/ruby-27-centos7",
},
Resolvers: cmd.Resolvers{
DockerSearcher: app.DockerClientSearcher{
Expand All @@ -1703,7 +1703,7 @@ func TestNewAppBuildOutputCycleDetection(t *testing.T) {
if err != nil {
return err
}
want := "--> WARNING: output image of \"centos/ruby-27-centos7:latest\" should be different than input\n"
want := "--> WARNING: output image of \"quay.io/centos7/ruby-27-centos7:latest\" should be different than input\n"
if string(got) != want {
return fmt.Errorf("stderr: got %q; want %q", got, want)
}
Expand All @@ -1715,8 +1715,8 @@ func TestNewAppBuildOutputCycleDetection(t *testing.T) {
config: &cmd.AppConfig{
GenerationInputs: cmd.GenerationInputs{
OutputDocker: true,
To: "centos/ruby-27-centos7",
Dockerfile: "FROM centos/ruby-27-centos7:latest",
To: "quay.io/centos7/ruby-27-centos7",
Dockerfile: "FROM quay.io/centos7/ruby-27-centos7:latest",
},
Resolvers: cmd.Resolvers{
DockerSearcher: app.DockerClientSearcher{
Expand All @@ -1735,7 +1735,7 @@ func TestNewAppBuildOutputCycleDetection(t *testing.T) {
if err != nil {
return err
}
want := "--> WARNING: output image of \"centos/ruby-27-centos7:latest\" should be different than input\n"
want := "--> WARNING: output image of \"quay.io/centos7/ruby-27-centos7:latest\" should be different than input\n"
if string(got) != want {
return fmt.Errorf("stderr: got %q; want %q", got, want)
}
Expand Down Expand Up @@ -1816,7 +1816,7 @@ func TestNewAppNewBuildEnvVars(t *testing.T) {
config: &cmd.AppConfig{
ComponentInputs: cmd.ComponentInputs{
SourceRepositories: []string{"https://github.com/openshift/ruby-hello-world"},
DockerImages: []string{"centos/ruby-27-centos7", "openshift/nodejs-010-centos7"},
DockerImages: []string{"quay.io/centos7/ruby-27-centos7", "registry.centos.org/centos/nodejs-12-centos7"},
},
GenerationInputs: cmd.GenerationInputs{
OutputDocker: true,
Expand Down Expand Up @@ -1892,7 +1892,7 @@ func TestNewAppBuildConfigEnvVarsAndSecrets(t *testing.T) {
config: &cmd.AppConfig{
ComponentInputs: cmd.ComponentInputs{
SourceRepositories: []string{"https://github.com/openshift/ruby-hello-world"},
DockerImages: []string{"centos/ruby-27-centos7", "centos/mongodb-26-centos7"},
DockerImages: []string{"quay.io/centos7/ruby-27-centos7", "registry.centos.org/centos/mongodb-34-centos7"},
},
GenerationInputs: cmd.GenerationInputs{
OutputDocker: true,
Expand Down Expand Up @@ -2327,7 +2327,7 @@ func fakeDockerSearcher() app.Searcher {
func fakeSimpleDockerSearcher() app.Searcher {
return app.DockerClientSearcher{
Client: &apptest.FakeDockerClient{
Images: []docker.APIImages{{RepoTags: []string{"centos/ruby-27-centos7"}}},
Images: []docker.APIImages{{RepoTags: []string{"quay.io/centos7/ruby-27-centos7"}}},
Image: &docker.Image{
ID: "ruby",
Config: &docker.Config{
Expand Down