本文整理汇总了Golang中github.com/openshift/origin/pkg/dockerregistry.NewClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClient函数的具体用法?Golang NewClient怎么用?Golang NewClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewClient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Next
func (c *ImportController) Next(stream *api.ImageStream) error {
if !needsImport(stream) {
return nil
}
insecure := stream.Annotations[api.InsecureRepositoryAnnotation] == "true"
client := c.client
if client == nil {
client = dockerregistry.NewClient()
}
toImport, err := getTags(stream, client, insecure)
// return here, only if there is an error and nothing to import
if err != nil && len(toImport) == 0 {
return err
}
errs := c.importTags(stream, toImport, client, insecure)
// one of retry-able error happened, we need to inform the RetryController
// the import should be retried by returning error
if len(errs) > 0 {
return kerrors.NewAggregate(errs)
}
if err != nil {
return err
}
return c.done(stream, "", retryCount)
}
示例2: TestRegistryClientConnect
func TestRegistryClientConnect(t *testing.T) {
c := dockerregistry.NewClient()
conn, err := c.Connect("docker.io", false)
if err != nil {
t.Fatal(err)
}
for _, s := range []string{"index.docker.io", "https://docker.io", "https://index.docker.io"} {
otherConn, err := c.Connect(s, false)
if err != nil {
t.Errorf("%s: can't connect: %v", s, err)
continue
}
if !reflect.DeepEqual(otherConn, conn) {
t.Errorf("%s: did not reuse connection: %#v %#v", s, conn, otherConn)
}
}
otherConn, err := c.Connect("index.docker.io:443", false)
if err != nil || reflect.DeepEqual(otherConn, conn) {
t.Errorf("should not have reused index.docker.io:443: %v", err)
}
if _, err := c.Connect("http://ba%3/", false); err == nil {
t.Error("Unexpected non-error")
}
}
示例3: PrepareAppConfig
// PrepareAppConfig sets fields in config appropriate for running tests. It
// returns two buffers bound to stdout and stderr.
func PrepareAppConfig(config *cmd.AppConfig) (stdout, stderr *bytes.Buffer) {
config.ExpectToBuild = true
stdout, stderr = new(bytes.Buffer), new(bytes.Buffer)
config.Out, config.ErrOut = stdout, stderr
config.Detector = app.SourceRepositoryEnumerator{
Detectors: source.DefaultDetectors,
Tester: dockerfile.NewTester(),
}
config.DockerSearcher = app.DockerRegistrySearcher{
Client: dockerregistry.NewClient(10*time.Second, true),
}
config.ImageStreamByAnnotationSearcher = fakeImageStreamSearcher()
config.ImageStreamSearcher = fakeImageStreamSearcher()
config.OriginNamespace = "default"
config.OSClient = &client.Fake{}
config.RefBuilder = &app.ReferenceBuilder{}
config.TemplateSearcher = app.TemplateSearcher{
Client: &client.Fake{},
TemplateConfigsNamespacer: &client.Fake{},
Namespaces: []string{"openshift", "default"},
}
config.Typer = kapi.Scheme
return
}
示例4: TestRegistryClientImage
func TestRegistryClientImage(t *testing.T) {
for _, v2 := range []bool{true, false} {
host := "index.docker.io"
if !v2 {
host = "registry.hub.docker.com"
}
conn, err := dockerregistry.NewClient().Connect(host, false)
if err != nil {
t.Fatal(err)
}
if _, err := conn.ImageByTag("openshift", "origin-not-found", "latest"); !dockerregistry.IsRepositoryNotFound(err) && !dockerregistry.IsTagNotFound(err) {
t.Errorf("V2=%t: unexpected error: %v", v2, err)
}
image, err := conn.ImageByTag("openshift", "origin", "latest")
if err != nil {
t.Fatalf("V2=%t: %v", v2, err)
}
if len(image.ContainerConfig.Entrypoint) == 0 {
t.Errorf("V2=%t: unexpected image: %#v", v2, image)
}
if v2 && !image.PullByID {
t.Errorf("V2=%t: should be able to pull by ID %s", v2, image.ID)
}
other, err := conn.ImageByID("openshift", "origin", image.ID)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(other.ContainerConfig.Entrypoint, image.ContainerConfig.Entrypoint) {
t.Errorf("V2=%t: unexpected image: %#v", v2, other)
}
}
}
示例5: Create
// Create creates an ImportController.
func (f *ImportControllerFactory) Create() controller.RunnableController {
lw := &cache.ListWatch{
ListFunc: func() (runtime.Object, error) {
return f.Client.ImageStreams(kapi.NamespaceAll).List(labels.Everything(), fields.Everything())
},
WatchFunc: func(resourceVersion string) (watch.Interface, error) {
return f.Client.ImageStreams(kapi.NamespaceAll).Watch(labels.Everything(), fields.Everything(), resourceVersion)
},
}
q := cache.NewFIFO(cache.MetaNamespaceKeyFunc)
cache.NewReflector(lw, &api.ImageStream{}, q, 2*time.Minute).Run()
c := &ImportController{
client: dockerregistry.NewClient(),
streams: f.Client,
mappings: f.Client,
}
return &controller.RetryController{
Queue: q,
RetryManager: controller.NewQueueRetryManager(
q,
cache.MetaNamespaceKeyFunc,
func(obj interface{}, err error, retries controller.Retry) bool {
util.HandleError(err)
return retries.Count < 5
},
kutil.NewTokenBucketRateLimiter(1, 10),
),
Handle: func(obj interface{}) error {
r := obj.(*api.ImageStream)
return c.Next(r)
},
}
}
示例6: TestRegistryClientV2DockerHub
func TestRegistryClientV2DockerHub(t *testing.T) {
c := dockerregistry.NewClient()
conn, err := c.Connect("index.docker.io", false)
if err != nil {
t.Fatal(err)
}
image, err := conn.ImageByTag("kubernetes", "guestbook", "latest")
// The V2 docker hub registry seems to have a bug for this repo, should eventually get fixed
if !dockerregistry.IsTagNotFound(err) {
t.Fatalf("unexpected error: %v", err)
}
// a v1 only path
conn, err = c.Connect("registry.hub.docker.com", false)
if err != nil {
t.Fatal(err)
}
image, err = conn.ImageByTag("kubernetes", "guestbook", "latest")
if err != nil {
t.Fatalf("unable to retrieve image info: %v", err)
}
if len(image.ID) == 0 {
t.Fatalf("image had no ID: %#v", image)
}
}
示例7: TestNewBuildEnvVars
func TestNewBuildEnvVars(t *testing.T) {
dockerSearcher := app.DockerRegistrySearcher{
Client: dockerregistry.NewClient(),
}
tests := []struct {
name string
config *AppConfig
expected []kapi.EnvVar
expectedErr error
}{
{
name: "explicit environment variables for buildConfig and deploymentConfig",
config: &AppConfig{
AddEnvironmentToBuild: true,
SourceRepositories: util.StringList([]string{"https://github.com/openshift/ruby-hello-world"}),
DockerImages: util.StringList([]string{"openshift/ruby-20-centos7", "openshift/mongodb-24-centos7"}),
OutputDocker: true,
Environment: util.StringList([]string{"BUILD_ENV_1=env_value_1", "BUILD_ENV_2=env_value_2"}),
dockerSearcher: dockerSearcher,
detector: app.SourceRepositoryEnumerator{
Detectors: source.DefaultDetectors,
Tester: dockerfile.NewTester(),
},
typer: kapi.Scheme,
osclient: &client.Fake{},
originNamespace: "default",
},
expected: []kapi.EnvVar{
{Name: "BUILD_ENV_1", Value: "env_value_1"},
{Name: "BUILD_ENV_2", Value: "env_value_2"},
},
expectedErr: nil,
},
}
for _, test := range tests {
test.config.refBuilder = &app.ReferenceBuilder{}
test.config.Out, test.config.ErrOut = os.Stdout, os.Stderr
res, err := test.config.RunBuilds()
if err != test.expectedErr {
t.Errorf("%s: Error mismatch! Expected %v, got %v", test.name, test.expectedErr, err)
continue
}
got := []kapi.EnvVar{}
for _, obj := range res.List.Items {
switch tp := obj.(type) {
case *buildapi.BuildConfig:
got = tp.Spec.Strategy.SourceStrategy.Env
break
}
}
if !reflect.DeepEqual(test.expected, got) {
t.Errorf("%s: unexpected output. Expected: %#v, Got: %#v", test.name, test.expected, got)
continue
}
}
}
示例8: TestRegistryClientRegistryNotFound
func TestRegistryClientRegistryNotFound(t *testing.T) {
conn, err := dockerregistry.NewClient().Connect("localhost:65000", false)
if err != nil {
t.Fatal(err)
}
if _, err := conn.ImageByID("foo", "bar", "baz"); !dockerregistry.IsRegistryNotFound(err) {
t.Error(err)
}
}
示例9: TestRegistryClientQuayIOImage
func TestRegistryClientQuayIOImage(t *testing.T) {
conn, err := dockerregistry.NewClient().Connect("quay.io", false)
if err != nil {
t.Fatal(err)
}
if _, err := conn.ImageByTag("coreos", "etcd", "latest"); err != nil {
t.Errorf("unexpected error: %v", err)
}
}
示例10: TestNewAppDetectSource
func TestNewAppDetectSource(t *testing.T) {
skipExternalGit(t)
gitLocalDir := createLocalGitDirectory(t)
defer os.RemoveAll(gitLocalDir)
dockerSearcher := app.DockerRegistrySearcher{
Client: dockerregistry.NewClient(10*time.Second, true),
}
mocks := MockSourceRepositories(t, gitLocalDir)
tests := []struct {
name string
cfg *cmd.AppConfig
repositories []*app.SourceRepository
expectedLang string
expectedErr string
}{
{
name: "detect source - ruby",
cfg: &cmd.AppConfig{
Detector: app.SourceRepositoryEnumerator{
Detectors: source.DefaultDetectors,
Tester: dockerfile.NewTester(),
},
DockerSearcher: dockerSearcher,
},
repositories: []*app.SourceRepository{mocks[0]},
expectedLang: "ruby",
expectedErr: "",
},
}
for _, test := range tests {
err := test.cfg.DetectSource(test.repositories)
if err != nil {
if !strings.Contains(err.Error(), test.expectedErr) {
t.Errorf("%s: Invalid error: Expected %s, got %v", test.name, test.expectedErr, err)
}
} else if len(test.expectedErr) != 0 {
t.Errorf("%s: Expected %s error but got none", test.name, test.expectedErr)
}
for _, repo := range test.repositories {
info := repo.Info()
if info == nil {
t.Errorf("%s: expected repository info to be populated; it is nil", test.name)
continue
}
if term := strings.Join(info.Terms(), ","); term != test.expectedLang {
t.Errorf("%s: expected repository info term to be %s; got %s\n", test.name, test.expectedLang, term)
}
}
}
}
示例11: NewAppConfig
// NewAppConfig returns a new AppConfig, but you must set your typer, mapper, and clientMapper after the command has been run
// and flags have been parsed.
func NewAppConfig() *AppConfig {
dockerSearcher := app.DockerRegistrySearcher{
Client: dockerregistry.NewClient(),
}
return &AppConfig{
detector: app.SourceRepositoryEnumerator{
Detectors: source.DefaultDetectors,
Tester: dockerfile.NewTester(),
},
dockerSearcher: dockerSearcher,
refBuilder: &app.ReferenceBuilder{},
}
}
示例12: TestRegistryClientQuayIOImage
func TestRegistryClientQuayIOImage(t *testing.T) {
for _, v2 := range []bool{true, false} {
conn, err := dockerregistry.NewClient().Connect("quay.io", false, v2)
if err != nil {
t.Fatal(err)
}
_, err = conn.ImageByTag("coreos", "etcd", "latest")
if err != nil {
t.Errorf("v2=%t: unexpected error: %v", v2, err)
}
}
}
示例13: TestRegistryClientQuayIOImage
func TestRegistryClientQuayIOImage(t *testing.T) {
conn, err := dockerregistry.NewClient().Connect("quay.io", false)
if err != nil {
t.Fatal(err)
}
err = retryWhenUnreachable(t, func() error {
_, err := conn.ImageByTag("coreos", "etcd", "latest")
return err
})
if err != nil {
t.Skip("SKIPPING: unexpected error from quay.io: %v", err)
}
}
示例14: TestRegistryClientConnectPulpRegistry
func TestRegistryClientConnectPulpRegistry(t *testing.T) {
c := dockerregistry.NewClient()
conn, err := c.Connect("registry.access.redhat.com", false)
if err != nil {
t.Fatal(err)
}
image, err := conn.ImageByTag("library", "rhel", "latest")
if err != nil {
t.Fatalf("unable to retrieve image info: %v", err)
}
if len(image.ID) == 0 {
t.Fatalf("image had no ID: %#v", image)
}
}
示例15: TestDetectSource
func TestDetectSource(t *testing.T) {
dockerResolver := app.DockerRegistryResolver{
Client: dockerregistry.NewClient(),
}
mocks := app.MockSourceRepositories()
tests := []struct {
name string
cfg *AppConfig
repositories []*app.SourceRepository
expectedLang string
expectedErr string
}{
{
name: "detect source - ruby",
cfg: &AppConfig{
detector: app.SourceRepositoryEnumerator{
Detectors: source.DefaultDetectors,
Tester: dockerfile.NewTester(),
},
dockerResolver: dockerResolver,
},
repositories: []*app.SourceRepository{mocks[1]},
expectedLang: "ruby",
expectedErr: "",
},
}
for _, test := range tests {
err := test.cfg.detectSource(test.repositories)
if err != nil {
if !strings.Contains(err.Error(), test.expectedErr) {
t.Errorf("%s: Invalid error: Expected %s, got %v", test.name, test.expectedErr, err)
}
} else if len(test.expectedErr) != 0 {
t.Errorf("%s: Expected %s error but got none", test.name, test.expectedErr)
}
for _, repo := range test.repositories {
info := repo.Info()
if info == nil {
t.Errorf("%s: expected repository info to be populated; it is nil", test.name)
continue
}
if term := strings.Join(info.Terms(), ","); term != test.expectedLang {
t.Errorf("%s: expected repository info term to be %s; got %s\n", test.name, test.expectedLang, term)
}
}
}
}