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

OPCT-242: Introduce command 'get images' #83

Merged
merged 5 commits into from
Oct 17, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/spf13/viper"
"github.com/vmware-tanzu/sonobuoy/cmd/sonobuoy/app"

"github.com/redhat-openshift-ecosystem/provider-certification-tool/pkg/cmd/get"
"github.com/redhat-openshift-ecosystem/provider-certification-tool/pkg/destroy"
"github.com/redhat-openshift-ecosystem/provider-certification-tool/pkg/report"
"github.com/redhat-openshift-ecosystem/provider-certification-tool/pkg/retrieve"
Expand Down Expand Up @@ -72,6 +73,7 @@ func init() {
rootCmd.AddCommand(status.NewCmdStatus())
rootCmd.AddCommand(version.NewCmdVersion())
rootCmd.AddCommand(report.NewCmdReport())
rootCmd.AddCommand(get.NewCmdGet())

// Link in child commands direct from Sonobuoy
rootCmd.AddCommand(app.NewSonobuoyCommand())
Expand Down
46 changes: 35 additions & 11 deletions docs/user-installation-disconnected.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# User Installation Guide - Disconnected Installations

## Prerequisites/Requirements
## Prerequisites

- Disconnected Mirror Image Registry created
- [Private cluster Installed](https://docs.openshift.com/container-platform/latest/installing/installing_bare_metal/installing-restricted-networks-bare-metal.html)
- [You created a registry on your mirror host](https://docs.openshift.com/container-platform/latest/installing/disconnected_install/installing-mirroring-installation-images.html#installing-mirroring-installation-images)

## Configuring the Disconnected Mirror Registry

### Mirror images used by conformance suite

1. Extract the `openshift-tests` executable associated with the version of OpenShift you are installing.
_Note:_ The pull secret must contain both your OpenShift pull secret as well credentials for the disconnected
mirror registry.
~~~

~~~sh
PULL_SECRET=/path/to/pull-secret
OPENSHIFT_TESTS_IMAGE=$(oc get is -n openshift tests -o=jsonpath='{.spec.tags[0].from.name}')
oc image extract -a ${PULL_SECRET} "${OPENSHIFT_TESTS_IMAGE}" --file="/usr/bin/openshift-tests"
Expand All @@ -19,38 +23,58 @@ chmod +x openshift-tests

2. Extract the images and the location to where they are to be mirrored from the `openshift-tests` executable.

~~~
~~~sh
TARGET_REPO=target-registry.net/ocp-cert
./openshift-tests images --to-repository ${TARGET_REPO} > images-to-mirror
~~~

3. Append Sonobuoy to the `images-to-mirror` list
~~~
### Mirror images used by test environment

For OPCT **v0.4.x** and older:

3. A) Append Sonobuoy to the `images-to-mirror` list

~~~sh
SONOBUOY_TAG=$(./openshift-provider-cert-linux-amd64 version | grep "Sonobuoy Version:" | cut -d' ' -f 3)
SONOBUOY_TARGET=${TARGET_REPO}/sonobuoy:${SONOBUOY_TAG}
echo "quay.io/ocp-cert/sonobuoy:${SONOBUOY_TAG} ${SONOBUOY_TARGET}" >> images-to-mirror
~~~

4. Append the OPCT tools image to the `images-to-mirror` list
3. B) Append the OPCT tools image to the `images-to-mirror` list:

~~~
OPCT_VERSION=v0.4.0-alpha1
~~~sh
OPCT_VERSION=v0.4.1
OPCT_TARGET=${TARGET_REPO}/openshift-tests-provider-cert:${OPCT_VERSION}
echo "quay.io/ocp-cert/openshift-tests-provider-cert:${OPCT_VERSION} ${OPCT_TARGET}" >> images-to-mirror
~~~

5. Mirror the images to the disconnected mirror registry
3. C) Append extra images used by conformance tool to the `images-to-mirror` list:

~~~sh
PAUSE_TARGET=${TARGET_REPO}/ocp-cert:e2e-28-registry-k8s-io-pause-3-8-aP7uYsw5XCmoDy5W
echo "registry.k8s.io/pause:3.8 ${PAUSE_TARGET}" >> images-to-mirror
~~~
oc image mirror -a ${PULL_SECRET} -f images-to-mirror

For OPCT **v0.5.0** and newer:

3. Append images used by OPCT to the `images-to-mirror` list:

~~~sh
./opct get images --to-repository ${TARGET_REPO} >> images-to-mirror
~~~

### Mirror the images

4. Mirror the images to the disconnected mirror registry

~~~sh
oc image mirror -a ${PULL_SECRET} -f images-to-mirror
~~~

## Preparing Your Cluster

- The Insights operator must be disabled prior to to running tests. See [Disabling insights operator](https://docs.openshift.com/container-platform/latest/support/remote_health_monitoring/opting-out-of-remote-health-reporting.html)
- The [Image Registry Operator](https://docs.openshift.com/container-platform/latest/registry/index.html) must be configured and available



For additional details and configuration options, see [User Guide](./user.md).
70 changes: 70 additions & 0 deletions pkg/cmd/get/images.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package get

import (
"fmt"

"github.com/redhat-openshift-ecosystem/provider-certification-tool/pkg"
"github.com/spf13/cobra"
"github.com/vmware-tanzu/sonobuoy/pkg/buildinfo"
)

type imageOptions struct {
ToRepository string
}

var options *imageOptions

var imagesCmd = &cobra.Command{
Use: "images",
Short: "Print images used by OPCT.",
Run: runGetImages,
}

func init() {
options = new(imageOptions)
imagesCmd.Flags().StringVar(&options.ToRepository, "to-repository", "", "Show images with format to mirror to repository. Example: registry.example.io:5000")
}

func generateImage(repo, name string) string {
if options.ToRepository == "" {
return fmt.Sprintf("%s/%s", repo, name)
} else {
from := fmt.Sprintf("%s/%s", repo, name)
to := fmt.Sprintf("%s/%s", options.ToRepository, name)
return fmt.Sprintf("%s %s", from, to)
}
}

func runGetImages(cmd *cobra.Command, args []string) {

images := []string{}

// Sonobuoy
images = append(images, generateImage("quay.io/ocp-cert", fmt.Sprintf("sonobuoy:%s", buildinfo.Version)))

// Plugins
images = append(images, generateImage("quay.io/ocp-cert", pkg.PluginsImage))
images = append(images, generateImage("quay.io/opct", "must-gather-monitoring:v0.1.0"))

// etcdfio
img_etcdfio := "quay.io/openshift-scale/etcd-perf:latest"
if options.ToRepository == "" {
images = append(images, img_etcdfio)
} else {
to := fmt.Sprintf("%s/%s", options.ToRepository, "etcd-perf:latest")
images = append(images, fmt.Sprintf("%s %s", img_etcdfio, to))
}

// test's specific images (not related with OPCT)
img_e2epause := "registry.k8s.io/pause:3.8"
if options.ToRepository == "" {
images = append(images, img_e2epause)
} else {
to := fmt.Sprintf("%s/%s", options.ToRepository, "ocp-cert:e2e-28-registry-k8s-io-pause-3-8-aP7uYsw5XCmoDy5W")
images = append(images, fmt.Sprintf("%s %s", img_e2epause, to))
}

for _, image := range images {
fmt.Println(image)
}
}
25 changes: 25 additions & 0 deletions pkg/cmd/get/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package get

import (
"fmt"

"github.com/spf13/cobra"
)

var getCmd = &cobra.Command{
Use: "get",
Short: "Get tool information.",
Run: runGet,
}

func init() {
getCmd.AddCommand(imagesCmd)
}

func NewCmdGet() *cobra.Command {
return getCmd
}

func runGet(cmd *cobra.Command, args []string) {
fmt.Println("Nothing to do. See -h for more options.")
}
2 changes: 1 addition & 1 deletion pkg/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const (
SonobuoyLabelComponentName = "component"
SonobuoyLabelComponentValue = "sonobuoy"
DefaultToolsRepository = "quay.io/ocp-cert"
PluginsImage = "openshift-tests-provider-cert:v0.4.0"
PluginsImage = "openshift-tests-provider-cert:v0.5.0-alpha.1"
)

var (
Expand Down