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

Add the ability to check a container from another platform #829

Merged
merged 1 commit into from
Nov 10, 2022
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
1 change: 1 addition & 0 deletions certification/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type containerConfig interface {
PyxisHost() string
PyxisAPIToken() string
Submit() bool
Platform() string
}

// operatorConfig are configurables relevant to
Expand Down
3 changes: 1 addition & 2 deletions certification/internal/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"path"
"path/filepath"
"regexp"
goruntime "runtime"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -81,7 +80,7 @@ func (c *CraneEngine) ExecuteChecks(ctx context.Context) error {
),
crane.WithPlatform(&cranev1.Platform{
OS: "linux",
Architecture: goruntime.GOARCH,
Architecture: c.Config.Platform(),
}),
retryOnceAfter(5 * time.Second),
}
Expand Down
6 changes: 0 additions & 6 deletions certification/internal/policy/container/has_unique_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ package container
import (
"context"
"fmt"
goruntime "runtime"
"strings"

"github.com/redhat-openshift-ecosystem/openshift-preflight/certification"
"github.com/redhat-openshift-ecosystem/openshift-preflight/certification/internal/authn"

"github.com/google/go-containerregistry/pkg/crane"
cranev1 "github.com/google/go-containerregistry/pkg/v1"
)

var _ certification.Check = &hasUniqueTagCheck{}
Expand Down Expand Up @@ -59,10 +57,6 @@ func (p *hasUniqueTagCheck) getDataToValidate(ctx context.Context, image string)
options := []crane.Option{
crane.WithContext(ctx),
crane.WithAuthFromKeychain(authn.PreflightKeychain(authn.WithDockerConfig(p.dockercfg))),
crane.WithPlatform(&cranev1.Platform{
OS: "linux",
Architecture: goruntime.GOARCH,
}),
}

return crane.ListTags(image, options...)
Expand Down
3 changes: 2 additions & 1 deletion certification/runtime/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ func imageList(ctx context.Context) []string {
crane.WithContext(ctx),
crane.WithAuthFromKeychain(authn.PreflightKeychain()),
crane.WithPlatform(&cranev1.Platform{
OS: "linux",
OS: "linux",
// This remains the runtime arch, as we don't specify the arch for operators
Architecture: goruntime.GOARCH,
}),
}
Expand Down
2 changes: 2 additions & 0 deletions certification/runtime/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Config struct {
PyxisAPIToken string
DockerConfig string
Submit bool
Platform string
// Operator-Specific Fields
Namespace string
ServiceAccount string
Expand Down Expand Up @@ -63,6 +64,7 @@ func (c *Config) storeContainerPolicyConfiguration(vcfg viper.Viper) {
c.Submit = vcfg.GetBool("submit")
c.PyxisHost = pyxisHostLookup(vcfg.GetString("pyxis_env"), vcfg.GetString("pyxis_host"))
c.CertificationProjectID = vcfg.GetString("certification_project_id")
c.Platform = vcfg.GetString("platform")
}

// storeOperatorPolicyConfiguration reads operator-policy-specific config
Expand Down
4 changes: 4 additions & 0 deletions certification/runtime/config_read.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,7 @@ func (ro *ReadOnlyConfig) Kubeconfig() string {
func (ro *ReadOnlyConfig) IndexImage() string {
return ro.cfg.IndexImage
}

func (ro *ReadOnlyConfig) Platform() string {
return ro.cfg.Platform
}
2 changes: 2 additions & 0 deletions certification/runtime/config_read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var _ = Describe("Runtime ReadOnlyConfig test", func() {
PyxisAPIToken: "pyxisapitoken",
DockerConfig: "dockercfg",
Submit: true,
Platform: "s390x",
Namespace: "ns",
ServiceAccount: "sa",
ScorecardImage: "scorecardimg",
Expand All @@ -44,6 +45,7 @@ var _ = Describe("Runtime ReadOnlyConfig test", func() {
Expect(cro.PyxisAPIToken()).To(Equal("pyxisapitoken"))
Expect(cro.DockerConfig()).To(Equal("dockercfg"))
Expect(cro.Submit()).To(Equal(true))
Expect(cro.Platform()).To(Equal("s390x"))
Expect(cro.Namespace()).To(Equal("ns"))
Expect(cro.ServiceAccount()).To(Equal("sa"))
Expect(cro.ScorecardImage()).To(Equal("scorecardimg"))
Expand Down
4 changes: 3 additions & 1 deletion certification/runtime/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ var _ = Describe("Viper to Runtime Config", func() {
expectedRuntimeCfg.PyxisHost = "catalog.redhat.com/api/containers"
baseViperCfg.Set("certification_project_id", "000000000000")
expectedRuntimeCfg.CertificationProjectID = "000000000000"
baseViperCfg.Set("platform", "s390x")
expectedRuntimeCfg.Platform = "s390x"

baseViperCfg.Set("namespace", "myns")
expectedRuntimeCfg.Namespace = "myns"
Expand Down Expand Up @@ -66,6 +68,6 @@ var _ = Describe("Viper to Runtime Config", func() {
// accurate in confirming that the derived configuration from viper
// matches.
keys := reflect.TypeOf(Config{}).NumField()
Expect(keys).To(Equal(20))
Expect(keys).To(Equal(21))
})
})
4 changes: 4 additions & 0 deletions cmd/preflight/cmd/check_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
rt "runtime"
"strings"

"github.com/redhat-openshift-ecosystem/openshift-preflight/certification"
Expand Down Expand Up @@ -47,6 +48,9 @@ func checkContainerCmd() *cobra.Command {
"URL paramater. This value may differ from the PID on the overview page. (env: PFLT_CERTIFICATION_PROJECT_ID)"))
_ = viper.BindPFlag("certification_project_id", checkContainerCmd.Flags().Lookup("certification-project-id"))

checkContainerCmd.Flags().String("platform", rt.GOARCH, "Architecture of image to pull. Defaults to current platform.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice way to default!

_ = viper.BindPFlag("platform", checkContainerCmd.Flags().Lookup("platform"))

return checkContainerCmd
}

Expand Down