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

fix #1222: use image sha in s2i build to avoid knative registry resol… #1269

Merged
merged 1 commit into from
Feb 12, 2020
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
8 changes: 8 additions & 0 deletions deploy/resources.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion pkg/builder/s2i/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package s2i

import (
"fmt"
"io/ioutil"
"os"
"path"
Expand Down Expand Up @@ -154,9 +155,13 @@ func publisher(ctx *builder.Context) error {
return errors.Wrap(err, "cannot unmarshal instantiated binary response")
}

var sha string
err = kubernetes.WaitCondition(ctx.C, ctx.Client, &ocbuild, func(obj interface{}) (bool, error) {
if val, ok := obj.(*buildv1.Build); ok {
if val.Status.Phase == buildv1.BuildPhaseComplete {
if val.Status.Output.To != nil {
sha = val.Status.Output.To.ImageDigest
}
return true, nil
} else if val.Status.Phase == buildv1.BuildPhaseCancelled ||
val.Status.Phase == buildv1.BuildPhaseFailed ||
Expand Down Expand Up @@ -184,7 +189,14 @@ func publisher(ctx *builder.Context) error {
return errors.New("dockerImageRepository not available in ImageStream")
}

ctx.Image = is.Status.DockerImageRepository + ":" + ctx.Build.Meta.ResourceVersion
var image string
if sha != "" {
image = fmt.Sprintf("%s@%s", is.Status.DockerImageRepository, sha)
} else {
// fallback to using tag
image = fmt.Sprintf("%s:%s", is.Status.DockerImageRepository, ctx.Build.Meta.ResourceVersion)
}
ctx.Image = image

return nil
}
3 changes: 0 additions & 3 deletions pkg/trait/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,6 @@ func (t *cronTrait) getCronJobFor(e *Environment) *v1beta1.CronJob {
}
}

// Resolve registry host names when used
annotations["alpha.image.policy.openshift.io/resolve-names"] = "*"

cronjob := v1beta1.CronJob{
TypeMeta: metav1.TypeMeta{
Kind: "CronJob",
Expand Down
3 changes: 0 additions & 3 deletions pkg/trait/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,6 @@ func (t *deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment {
}
}

// Resolve registry host names when used
annotations["alpha.image.policy.openshift.io/resolve-names"] = "*"

deployment := appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Kind: "Deployment",
Expand Down
3 changes: 0 additions & 3 deletions pkg/trait/knative_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,6 @@ func (t *knativeServiceTrait) getServiceFor(e *Environment) *serving.Service {
}
}

// Resolve registry host names when used
annotations["alpha.image.policy.openshift.io/resolve-names"] = "*"

//
// Set Knative Scaling behavior
//
Expand Down