本文整理汇总了Golang中github.com/openshift/source-to-image/pkg/api.InjectionList类的典型用法代码示例。如果您正苦于以下问题:Golang InjectionList类的具体用法?Golang InjectionList怎么用?Golang InjectionList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InjectionList类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: AddBuildSecrets
// AddBuildSecrets adds the defined secrets into a build. The input format for
// the secrets is "<secretName>:<destinationDir>". The destinationDir is
// optional and when not specified the default is the current working directory.
func (r *SourceRepository) AddBuildSecrets(secrets []string) error {
injections := s2iapi.InjectionList{}
r.secrets = []buildapi.SecretBuildSource{}
for _, in := range secrets {
if err := injections.Set(in); err != nil {
return err
}
}
secretExists := func(name string) bool {
for _, s := range r.secrets {
if s.Secret.Name == name {
return true
}
}
return false
}
for _, in := range injections {
if ok, _ := validation.ValidateSecretName(in.SourcePath, false); !ok {
return fmt.Errorf("the %q must be valid secret name", in.SourcePath)
}
if secretExists(in.SourcePath) {
return fmt.Errorf("the %q secret can be used just once", in.SourcePath)
}
r.secrets = append(r.secrets, buildapi.SecretBuildSource{
Secret: kapi.LocalObjectReference{Name: in.SourcePath},
DestinationDir: in.DestinationDir,
})
}
return nil
}
示例2: exerciseInjectionBuild
func (i *integrationTest) exerciseInjectionBuild(tag, imageName string, injections []string) {
t := i.t
err := os.Mkdir("/tmp/s2i-test-dir", 0777)
if err != nil {
t.Errorf("Unable to create temporary directory: %v", err)
}
defer os.RemoveAll("/tmp/s2i-test-dir")
err = ioutil.WriteFile(filepath.Join("/tmp/s2i-test-dir/secret"), []byte("secret"), 0666)
if err != nil {
t.Errorf("Unable to write content to temporary injection file: %v", err)
}
injectionList := api.InjectionList{}
for _, i := range injections {
injectionList.Set(i)
}
config := &api.Config{
DockerConfig: dockerConfig(),
BuilderImage: imageName,
BuilderPullPolicy: api.DefaultBuilderPullPolicy,
Source: TestSource,
Tag: tag,
Injections: injectionList,
}
builder, err := strategies.GetStrategy(config)
if err != nil {
t.Fatalf("Unable to create builder: %v", err)
}
resp, err := builder.Build(config)
if err != nil {
t.Fatalf("Unexpected error occurred during build: %v", err)
}
if !resp.Success {
t.Fatalf("S2I build failed.")
}
i.checkForImage(tag)
containerID := i.createContainer(tag)
defer i.removeContainer(containerID)
// Check that the injected file is delivered to assemble script
i.fileExists(containerID, "/sti-fake/secret-delivered")
i.fileExists(containerID, "/sti-fake/relative-secret-delivered")
// Make sure the injected file does not exists in resulting image
files, err := util.ExpandInjectedFiles(injectionList)
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
for _, f := range files {
if exitCode := i.runInImage(tag, "test -s "+f); exitCode == 0 {
t.Errorf("The file must be empty: %q, we got %q", f, err)
}
}
}