-
Notifications
You must be signed in to change notification settings - Fork 494
MCO-2208: MCO-2125: Migrate mco registry units #6079
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
Open
ptalgulk01
wants to merge
3
commits into
openshift:main
Choose a base branch
from
ptalgulk01:migrate-mco-registry-units
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
test/extended-priv/testdata/files/add-image-tag-mirror-set.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| apiVersion: template.openshift.io/v1 | ||
| kind: Template | ||
| metadata: | ||
| name: image-tag-mirror-set | ||
| objects: | ||
| - kind: ImageTagMirrorSet | ||
| apiVersion: config.openshift.io/v1 | ||
| metadata: | ||
| name: "${NAME}" | ||
| spec: | ||
| imageTagMirrors: | ||
| - mirrors: | ||
| - mirror.example.com/redhat | ||
| source: registry.redhat.io/openshift4 | ||
| mirrorSourcePolicy: AllowContactingSource | ||
| parameters: | ||
| - name: NAME |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| apiVersion: template.openshift.io/v1 | ||
| kind: Template | ||
| metadata: | ||
| name: repository-mirror | ||
| objects: | ||
| - kind: ImageContentSourcePolicy | ||
| apiVersion: operator.openshift.io/v1alpha1 | ||
| metadata: | ||
| name: "${NAME}" | ||
| spec: | ||
| repositoryDigestMirrors: ${{REPOSITORYDIGESTMIRRORS}} | ||
| parameters: | ||
| - name: NAME | ||
| - name: REPOSITORYDIGESTMIRRORS | ||
| value: '[{"mirrors":["example.io/example/ubi-minimal", "example.com/example/ubi-minimal"], "source": "registry.access.redhat.com/ubi8/ubi-minimal"}]' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| package bootstrap | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
| "os/exec" | ||
| "strings" | ||
| "time" | ||
|
|
||
| util "github.com/openshift/machine-config-operator/test/extended-priv/util" | ||
| logger "github.com/openshift/machine-config-operator/test/extended-priv/util/logext" | ||
| ) | ||
|
|
||
| const ( | ||
| // EnvVarSSHCloudPrivAWSUser stores the environment variable for the AWS ssh user | ||
| EnvVarSSHCloudPrivAWSUser = "SSH_CLOUD_PRIV_AWS_USER" | ||
| ) | ||
|
|
||
| // AWSBSInfoProvider implements interface BSInfoProvider for AWS | ||
| type AWSBSInfoProvider struct{} | ||
|
|
||
| // GetIPs returns the IPs of the bootstrap machine if this machine exists in AWS | ||
| func (a AWSBSInfoProvider) GetIPs(oc *util.CLI) (*Ips, error) { | ||
| infraName, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("infrastructure", "cluster", "-o=jsonpath={.status.infrastructureName}").Output() | ||
| if err != nil { | ||
| logger.Errorf("Could not get bootstrap's IP in AWS. Unable to get infrastructure's name. Error: %s", err) | ||
| return nil, err | ||
| } | ||
|
|
||
| bootstrapName := infraName + "-bootstrap" | ||
|
|
||
| publicIP, err := awsCLIGetInstancePublicIP(bootstrapName) | ||
| if err != nil { | ||
| return nil, &InstanceNotFound{bootstrapName} | ||
| } | ||
| if publicIP == "" || publicIP == "None" { | ||
| logger.Infof("Bootstrap instance '%s' has no public IP or is terminated", bootstrapName) | ||
| return nil, &InstanceNotFound{bootstrapName} | ||
| } | ||
|
|
||
| privateIP, _ := awsCLIGetInstancePrivateIP(bootstrapName) | ||
| logger.Infof("Bootstrap instance '%s': publicIP=%s, privateIP=%s", bootstrapName, publicIP, privateIP) | ||
| return &Ips{PublicIPAddress: publicIP, PrivateIPAddress: privateIP}, nil | ||
| } | ||
|
|
||
| // GetSSHUser returns the user needed to connect to the bootstrap machine via ssh | ||
| func (a AWSBSInfoProvider) GetSSHUser() string { | ||
| if user, exists := os.LookupEnv(EnvVarSSHCloudPrivAWSUser); exists { | ||
| return user | ||
| } | ||
| return DefaultSSHUser | ||
| } | ||
|
|
||
| func awsCLIGetInstancePublicIP(instanceName string) (string, error) { | ||
| ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
| defer cancel() | ||
| out, err := exec.CommandContext(ctx, "aws", "ec2", "describe-instances", | ||
| "--filters", fmt.Sprintf("Name=tag:Name,Values=%s", instanceName), | ||
| "--query", "Reservations[0].Instances[0].PublicIpAddress", | ||
| "--output", "text", | ||
| ).Output() | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| result := strings.TrimSpace(string(out)) | ||
| if result == "null" { | ||
| return "", fmt.Errorf("no instance found with name %s", instanceName) | ||
| } | ||
| return result, nil | ||
| } | ||
|
|
||
| func awsCLIGetInstancePrivateIP(instanceName string) (string, error) { | ||
| ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
| defer cancel() | ||
| out, err := exec.CommandContext(ctx, "aws", "ec2", "describe-instances", | ||
| "--filters", fmt.Sprintf("Name=tag:Name,Values=%s", instanceName), | ||
| "--query", "Reservations[0].Instances[0].PrivateIpAddress", | ||
| "--output", "text", | ||
| ).Output() | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| return strings.TrimSpace(string(out)), nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package bootstrap | ||
|
|
||
| import ( | ||
| util "github.com/openshift/machine-config-operator/test/extended-priv/util" | ||
| logger "github.com/openshift/machine-config-operator/test/extended-priv/util/logext" | ||
| ) | ||
|
|
||
| const ( | ||
| // EnvVarSSHCloudPrivAzureUser stores the environment variable for the Azure ssh user | ||
| EnvVarSSHCloudPrivAzureUser = "SSH_CLOUD_PRIV_AZURE_USER" | ||
| ) | ||
|
|
||
| // AzureBSInfoProvider implements interface BSInfoProvider for Azure | ||
| type AzureBSInfoProvider struct{} | ||
|
|
||
| // GetIPs returns the IPs of the bootstrap machine if this machine exists in Azure. | ||
| // Azure bootstrap discovery is not yet implemented; returns InstanceNotFound so the test skips. | ||
| func (a AzureBSInfoProvider) GetIPs(oc *util.CLI) (*Ips, error) { | ||
| infraName, err := oc.WithoutNamespace().AsAdmin().Run("get").Args("infrastructure", "cluster", "-o=jsonpath={.status.infrastructureName}").Output() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| bootstrapName := infraName + "-bootstrap" | ||
| logger.Infof("Azure bootstrap discovery is not yet implemented, skipping bootstrap machine: %s", bootstrapName) | ||
| return nil, &InstanceNotFound{bootstrapName} | ||
| } | ||
|
|
||
| // GetSSHUser returns the user needed to connect to the bootstrap machine via ssh | ||
| func (a AzureBSInfoProvider) GetSSHUser() string { | ||
| return DefaultSSHUser | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| package bootstrap | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| util "github.com/openshift/machine-config-operator/test/extended-priv/util" | ||
| logger "github.com/openshift/machine-config-operator/test/extended-priv/util/logext" | ||
| ) | ||
|
|
||
| const ( | ||
| // EnvVarSSHCloudPrivKey stores the environment variable for the ssh private key path | ||
| EnvVarSSHCloudPrivKey = "SSH_CLOUD_PRIV_KEY" | ||
| // DefaultSSHUser is the default ssh user for bootstrap machines | ||
| DefaultSSHUser = "core" | ||
| ) | ||
|
|
||
| // InstanceNotFound reports an error because the bootstrap instance is not found. It can be used to skip the test case. | ||
| type InstanceNotFound struct{ InstanceName string } | ||
|
|
||
| // Error implements the error interface | ||
| func (inferr *InstanceNotFound) Error() string { | ||
| return fmt.Sprintf("Instance %s has 'terminated' status", inferr.InstanceName) | ||
| } | ||
|
|
||
| // BSInfoProvider any struct implementing this interface can be used to create a Bootstrap object. | ||
| type BSInfoProvider interface { | ||
| GetIPs(*util.CLI) (*Ips, error) | ||
| GetSSHUser() string | ||
| } | ||
|
|
||
| // Bootstrap contains the functionality regarding the bootstrap machine | ||
| type Bootstrap struct { | ||
| SSH util.SshClient | ||
| IPs Ips | ||
| } | ||
|
|
||
| // Ips struct to store the public and the private IPs of the bootstrap machine | ||
| type Ips struct { | ||
| PrivateIPAddress string | ||
| PublicIPAddress string | ||
| } | ||
|
|
||
| // GetBootstrap returns a bootstrap struct pointing to the bootstrap machine if it exists | ||
| func GetBootstrap(oc *util.CLI) (*Bootstrap, error) { | ||
| bsInfoProvider, err := GetBSInfoProvider(oc) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| bootstrapIPs, err := bsInfoProvider.GetIPs(oc.AsAdmin()) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| user := bsInfoProvider.GetSSHUser() | ||
| return buildBootstrap(user, *bootstrapIPs, 22), nil | ||
| } | ||
|
|
||
| // GetBSInfoProvider returns a struct implementing BSInfoProvider for the current platform | ||
| func GetBSInfoProvider(oc *util.CLI) (BSInfoProvider, error) { | ||
| platform := util.CheckPlatform(oc) | ||
| switch platform { | ||
| case "aws": | ||
| return AWSBSInfoProvider{}, nil | ||
| case "azure": | ||
| return AzureBSInfoProvider{}, nil | ||
| default: | ||
| return nil, fmt.Errorf("platform not supported. Cannot get bootstrap information for platform: %s", platform) | ||
| } | ||
| } | ||
|
|
||
| func buildBootstrap(user string, bootstrapIPs Ips, port int) *Bootstrap { | ||
| privateKey := util.GetSSHPrivateKey() | ||
| publicIP := bootstrapIPs.PublicIPAddress | ||
| logger.Infof("Creating bootstrap with ip '%s', user: '%s', private key: '%s', port '%d'", | ||
| publicIP, user, privateKey, port) | ||
| return &Bootstrap{ | ||
| SSH: util.SshClient{User: user, Host: publicIP, Port: port, PrivateKey: privateKey}, | ||
| IPs: bootstrapIPs, | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.