element_type
stringclasses 4
values | project_name
stringclasses 1
value | uuid
stringlengths 36
36
| name
stringlengths 0
346
| imports
stringlengths 0
2.67k
| structs
stringclasses 761
values | interfaces
stringclasses 22
values | file_location
stringclasses 545
values | code
stringlengths 26
8.07M
| global_vars
stringclasses 7
values | package
stringclasses 124
values | tags
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
function
|
openshift/openshift-tests-private
|
eb3d8b16-ccd5-4e66-886f-b2be5defc4cf
|
GetMachinesByPhaseOrFail
|
['MachineSet']
|
github.com/openshift/openshift-tests-private/test/extended/mco/machineset.go
|
func (ms MachineSet) GetMachinesByPhaseOrFail(phase string) []Machine {
ml, err := ms.GetMachinesByPhase(phase)
o.Expect(err).NotTo(o.HaveOccurred(), "Get machine by phase %s failed", phase)
o.Expect(ml).ShouldNot(o.BeEmpty(), "No machine found by phase %s in machineset %s", phase, ms.GetName())
return ml
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
6f0885d4-4b82-4ccd-bf0a-cb7d3cad6bea
|
GetNodes
|
['MachineSet']
|
github.com/openshift/openshift-tests-private/test/extended/mco/machineset.go
|
func (ms MachineSet) GetNodes() ([]*Node, error) {
machines, mErr := ms.GetMachines()
if mErr != nil {
return nil, mErr
}
nodes := []*Node{}
for _, m := range machines {
n, nErr := m.GetNode()
if nErr != nil {
return nil, nErr
}
nodes = append(nodes, n)
}
return nodes, nil
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
eff12bae-e33a-483a-83d3-0a60a24588ac
|
GetNodesOrFail
|
['MachineSet']
|
github.com/openshift/openshift-tests-private/test/extended/mco/machineset.go
|
func (ms MachineSet) GetNodesOrFail() []*Node {
nodes, err := ms.GetNodes()
o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Error getting the nodes that belong to %s", ms)
return nodes
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
4faca3f2-35d9-490c-8c7d-ae581ebbe1ba
|
WaitUntilReady
|
['"context"', '"time"', '"k8s.io/apimachinery/pkg/util/wait"']
|
['MachineSet']
|
github.com/openshift/openshift-tests-private/test/extended/mco/machineset.go
|
func (ms MachineSet) WaitUntilReady(duration string) error {
pDuration, err := time.ParseDuration(duration)
if err != nil {
logger.Errorf("Error parsing duration %s. Errot: %s", duration, err)
return err
}
immediate := false
pollerr := wait.PollUntilContextTimeout(context.TODO(), 20*time.Second, pDuration, immediate, func(_ context.Context) (bool, error) {
return ms.GetIsReady(), nil
})
return pollerr
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
35f8c6c6-1fd6-46ca-8a42-7c15e43a74f0
|
Duplicate
|
['"github.com/tidwall/sjson"']
|
['MachineSet']
|
github.com/openshift/openshift-tests-private/test/extended/mco/machineset.go
|
func (ms MachineSet) Duplicate(newName string) (*MachineSet, error) {
res, err := CloneResource(&ms, newName, ms.GetNamespace(),
// Extra modifications to
// 1. Create the resource with 0 replicas
// 2. modify the selector matchLabels
// 3. modify the selector template metadata labels
func(resString string) (string, error) {
newResString, err := sjson.Set(resString, "spec.replicas", 0)
if err != nil {
return "", err
}
newResString, err = sjson.Set(newResString, `spec.selector.matchLabels.machine\.openshift\.io/cluster-api-machineset`, newName)
if err != nil {
return "", err
}
newResString, err = sjson.Set(newResString, `spec.template.metadata.labels.machine\.openshift\.io/cluster-api-machineset`, newName)
if err != nil {
return "", err
}
return newResString, nil
},
)
if err != nil {
return nil, err
}
logger.Infof("A new machineset %s has been created by cloning %s", res.GetName(), ms.GetName())
return NewMachineSet(ms.oc, res.GetNamespace(), res.GetName()), nil
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
2757d5a8-4dd3-4952-9e13-5b9ec9c82edc
|
SetCoreOsBootImage
|
['"fmt"']
|
['MachineSet']
|
github.com/openshift/openshift-tests-private/test/extended/mco/machineset.go
|
func (ms MachineSet) SetCoreOsBootImage(coreosBootImage string) error {
// the coreOs boot image is stored differently in the machineset spec depending on the platform
// currently we only support testing the coresOs boot image in GCP platform.
patchCoreOsBootImagePath := GetCoreOSBootImagePath(exutil.CheckPlatform(ms.oc))
return ms.Patch("json", fmt.Sprintf(`[{"op": "add", "path": "%s", "value": "%s"}]`,
patchCoreOsBootImagePath, coreosBootImage))
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
d8e307c4-d6ec-4230-9eb7-7f6dfa160498
|
GetArchitecture
|
['"fmt"', '"strings"', '"github.com/openshift/openshift-tests-private/test/extended/util/architecture"']
|
['MachineSet']
|
github.com/openshift/openshift-tests-private/test/extended/mco/machineset.go
|
func (ms MachineSet) GetArchitecture() (*architecture.Architecture, error) {
labeledArch, err := ms.Get(`{.metadata.annotations.capacity\.cluster-autoscaler\.kubernetes\.io/labels}`)
if err != nil {
return nil, err
}
expectedFormat := "kubernetes.io/arch="
if !strings.Contains(labeledArch, "kubernetes.io/arch=") {
return nil, fmt.Errorf("The annotated architecture is not in the expected format. Annotation: %s. Expected format: %s${ARCH}",
labeledArch, expectedFormat)
}
return PtrTo(architecture.FromString(strings.Split(labeledArch, "kubernetes.io/arch=")[1])), nil
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
726ec6f3-01d0-419e-bea0-8ea51238d624
|
GetArchitectureOrFail
|
['"github.com/openshift/openshift-tests-private/test/extended/util/architecture"']
|
['MachineSet']
|
github.com/openshift/openshift-tests-private/test/extended/mco/machineset.go
|
func (ms MachineSet) GetArchitectureOrFail() *architecture.Architecture {
arch, err := ms.GetArchitecture()
o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Error getting the annotated architecture in %s", ms)
return arch
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
38854623-96d6-4ff5-9f1d-c5dc503fba75
|
SetArchitecture
|
['"fmt"']
|
['MachineSet']
|
github.com/openshift/openshift-tests-private/test/extended/mco/machineset.go
|
func (ms MachineSet) SetArchitecture(arch string) error {
return ms.Patch("json",
fmt.Sprintf(`[{"op": "add", "path": "/metadata/annotations/capacity.cluster-autoscaler.kubernetes.io~1labels", "value": "kubernetes.io/arch=%s"}]`,
arch))
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
b5727e78-9b41-4553-89e9-ec8afa471a0b
|
GetUserDataSecret
|
['MachineSet']
|
github.com/openshift/openshift-tests-private/test/extended/mco/machineset.go
|
func (ms MachineSet) GetUserDataSecret() (string, error) {
return ms.Get(`{.spec.template.spec.providerSpec.value.userDataSecret.name}`)
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
675cd29f-6b3f-4271-88cb-144cbb15ab6c
|
GetCoreOsBootImage
|
['MachineSet']
|
github.com/openshift/openshift-tests-private/test/extended/mco/machineset.go
|
func (ms MachineSet) GetCoreOsBootImage() (string, error) {
// the coreOs boot image is stored differently in the machineset spec depending on the platform
// currently we only support testing the coresOs boot image in GCP platform.
coreOsBootImagePath := ""
switch p := exutil.CheckPlatform(ms.oc); p {
case "aws":
coreOsBootImagePath = `{.spec.template.spec.providerSpec.value.ami.id}`
case "gcp":
coreOsBootImagePath = `{.spec.template.spec.providerSpec.value.disks[0].image}`
default:
e2e.Failf("Machineset.GetCoreOsBootImage method is only supported for GCP and AWS infrastructure")
}
return ms.Get(coreOsBootImagePath)
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
06b31ee8-58f2-4d9d-ba09-41552c98f44e
|
GetCoreOsBootImageOrFail
|
['MachineSet']
|
github.com/openshift/openshift-tests-private/test/extended/mco/machineset.go
|
func (ms MachineSet) GetCoreOsBootImageOrFail() string {
img, err := ms.GetCoreOsBootImage()
o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Error getting the coreos boot image value in %s", ms)
return img
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
f2c14fa6-0231-4ccc-a5a5-4b24907c4064
|
GetAll
|
['MachineSet', 'MachineSetList']
|
github.com/openshift/openshift-tests-private/test/extended/mco/machineset.go
|
func (msl *MachineSetList) GetAll() ([]MachineSet, error) {
allMSResources, err := msl.ResourceList.GetAll()
if err != nil {
return nil, err
}
allMS := make([]MachineSet, 0, len(allMSResources))
for _, msRes := range allMSResources {
allMS = append(allMS, *NewMachineSet(msl.oc, msRes.GetNamespace(), msRes.GetName()))
}
return allMS, nil
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
2999b18f-dacc-4296-b304-b7bd167cd3fe
|
GetAllOrFail
|
['MachineSet', 'MachineSetList']
|
github.com/openshift/openshift-tests-private/test/extended/mco/machineset.go
|
func (msl *MachineSetList) GetAllOrFail() []MachineSet {
allMs, err := msl.GetAll()
o.ExpectWithOffset(1, err).NotTo(o.HaveOccurred(), "Error getting the list of existing MachineSets")
return allMs
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
f9384435-a4c2-4a7b-988e-129e277ba2a3
|
duplicateMachinesetSecret
|
['"fmt"', '"github.com/tidwall/gjson"', '"github.com/tidwall/sjson"']
|
github.com/openshift/openshift-tests-private/test/extended/mco/machineset.go
|
func duplicateMachinesetSecret(oc *exutil.CLI, secretName, newName, newIgnitionVersion string) (*Secret, error) {
var (
currentSecret = NewSecret(oc, MachineAPINamespace, secretName)
err error
)
userData, udErr := currentSecret.GetDataValue("userData")
if udErr != nil {
logger.Errorf("Error getting userData info from secret %s -n %s.\n%s", secretName, MachineAPINamespace, udErr)
return nil, udErr
}
disableTemplating, dtErr := currentSecret.GetDataValue("disableTemplating")
if dtErr != nil {
logger.Errorf("Error getting disableTemplating info from secret %s -n %s.\n%s", secretName, MachineAPINamespace, dtErr)
return nil, dtErr
}
currentIgnitionVersionResult := gjson.Get(userData, "ignition.version")
if !currentIgnitionVersionResult.Exists() || currentIgnitionVersionResult.String() == "" {
logger.Debugf("Could not get ignition version from ignition userData: %s", userData)
return nil, fmt.Errorf("Could not get ignition version from ignition userData. Enable debug GINKGO_TEST_ENABLE_DEBUG_LOG to get more info")
}
currentIgnitionVersion := currentIgnitionVersionResult.String()
if CompareVersions(currentIgnitionVersion, "==", newIgnitionVersion) {
logger.Infof("Current ignition version %s is the same as the new ignition version %s. No need to manipulate the userData info",
currentIgnitionVersion, newIgnitionVersion)
} else {
if CompareVersions(newIgnitionVersion, "<", "3.0.0") {
logger.Infof("New ignition version is %s, we need to adapt the userData ignition config to 2.0 config", newIgnitionVersion)
logger.Infof("Replace the 'merge' action with the 'append' action")
merge := gjson.Get(userData, "ignition.config.merge")
if !merge.Exists() {
logger.Debugf("Could not find the 'merge' information in the userData ignition config: %s", userData)
return nil, fmt.Errorf("Could not find the 'merge' information in the userData ignition config. Enable debug GINKGO_TEST_ENABLE_DEBUG_LOG to get more info")
}
userData, err = sjson.SetRaw(userData, "ignition.config.append", merge.String())
if err != nil {
return nil, err
}
userData, err = sjson.Delete(userData, "ignition.config.merge")
if err != nil {
return nil, err
}
}
logger.Infof("Replace ignition version '%s' with version '%s'", currentIgnitionVersion, newIgnitionVersion)
userData, err = sjson.Set(userData, "ignition.version", newIgnitionVersion)
if err != nil {
return nil, err
}
}
logger.Debugf("New userData info:\n%s", userData)
_, err = oc.AsAdmin().WithoutNamespace().Run("create").Args("secret", "generic", newName, "-n", MachineAPINamespace,
"--from-literal", fmt.Sprintf("userData=%s", userData),
"--from-literal", fmt.Sprintf("disableTemplating=%s", disableTemplating)).Output()
return NewSecret(oc.AsAdmin(), MachineAPINamespace, newName), err
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
0e051426-20cc-4c6c-9816-1fc3bb3e1a44
|
getUserDataIgnitionVersionFromOCPVersion
|
github.com/openshift/openshift-tests-private/test/extended/mco/machineset.go
|
func getUserDataIgnitionVersionFromOCPVersion(baseImageVersion string) string {
/* UserData ignition version is defined in https://github.com/openshift/installer/blob/release-4.16/pkg/asset/ignition/machine/node.go#L52
4.16: 3.2.0
4.15: 3.2.0
4.14: 3.2.0
4.13: 3.2.0 // change to rhel9
4.12: 3.2.0
4.11: 3.2.0 // support for arm64 added
4.10: 3.1.0
4.9: 3.1.0
4.8: 3.1.0
4.7: 3.1.0
4.6: 3.1.0
4.5: 2.2.0
4.4: 2.2.0
4.3: 2.2.0 // support for fips
4.2: 2.2.0
4.1: 2.2.0
*/
if CompareVersions(baseImageVersion, "<", "4.6") {
return "2.2.0"
}
if CompareVersions(baseImageVersion, "<", "4.10") {
return "3.1.0"
}
return "3.2.0"
}
|
mco
| |||||
function
|
openshift/openshift-tests-private
|
85651eb8-fd59-419b-8ad8-a3e8265dcb96
|
GetCoreOSBootImagePath
|
github.com/openshift/openshift-tests-private/test/extended/mco/machineset.go
|
func GetCoreOSBootImagePath(platform string) string {
patchCoreOsBootImagePath := ""
switch platform {
case AWSPlatform:
patchCoreOsBootImagePath = "/spec/template/spec/providerSpec/value/ami/id"
case GCPPlatform:
patchCoreOsBootImagePath = "/spec/template/spec/providerSpec/value/disks/0/image"
case VspherePlatform:
patchCoreOsBootImagePath = "/spec/template/spec/providerSpec/value/template"
default:
e2e.Failf("Machineset.GetCoreOsBootImage method is only supported for GCP and AWS platforms")
}
return patchCoreOsBootImagePath
}
|
mco
| |||||
function
|
openshift/openshift-tests-private
|
4a8cfc1a-82ac-4a35-9243-61ca5b417382
|
GetArchitectureFromMachineset
|
['"fmt"', '"github.com/openshift/openshift-tests-private/test/extended/util/architecture"']
|
['MachineSet']
|
github.com/openshift/openshift-tests-private/test/extended/mco/machineset.go
|
func GetArchitectureFromMachineset(ms *MachineSet, platform string) (architecture.Architecture, error) {
logger.Infof("Getting architecture for machineset %s", ms.GetName())
arch, err := ms.GetArchitecture()
if err == nil {
return *arch, nil
}
// In vsphere the machinesets are not annotated, so wee need to get the architecture from the Nodes if they exist
if platform != VspherePlatform {
return architecture.UNKNOWN, err
}
logger.Infof("In vsphere we need to get the architecture from the existing nodes created by the machineset %s", ms.GetName())
nodes, err := ms.GetNodes()
if err != nil {
return architecture.UNKNOWN, err
}
if len(nodes) == 0 {
return architecture.UNKNOWN, fmt.Errorf("Machineset %s has no replicas, so we cannot get the architecture from any existing node", ms.GetName())
}
narch, err := nodes[0].GetArchitecture()
if err != nil {
return architecture.UNKNOWN, err
}
return narch, nil
}
|
mco
| |||
file
|
openshift/openshift-tests-private
|
c8f4ad10-904e-4b83-a695-1c63e4d32fb1
|
const
|
import (
"time"
)
|
github.com/openshift/openshift-tests-private/test/extended/mco/const.go
|
// Package mco stores all MCO automated test cases
package mco
import (
"time"
)
const (
// MachineConfigNamespace mco namespace
MachineConfigNamespace = "openshift-machine-config-operator"
// MachineConfigDaemon mcd container name
MachineConfigDaemon = "machine-config-daemon"
// MachineConfigOperator mco container name
MachineConfigOperator = "machine-config-operator"
// MachineConfigDaemonEvents cluster role binding
MachineConfigDaemonEvents = "machine-config-daemon-events"
// MachineConfigPoolMaster master pool name
MachineConfigPoolMaster = "master"
// MachineConfigPoolWorker worker pool name
MachineConfigPoolWorker = "worker"
// ControllerDeployment name of the deployment deploying the machine config controller
ControllerDeployment = "machine-config-controller"
// ControllerContainer name of the controller container in the controller pod
ControllerContainer = "machine-config-controller"
// ControllerLabel label used to identify the controller pod
ControllerLabel = "k8s-app"
// ControllerLabelValue value used to identify the controller pod
ControllerLabelValue = "machine-config-controller"
// EnvVarLayeringTestImageRepository environment variable to define the image repository used by layering test cases
EnvVarLayeringTestImageRepository = "LAYERING_TEST_IMAGE_REPOSITORY"
// DefaultLayeringQuayRepository the quay repository that will be used by default to push auxiliary layering images
DefaultLayeringQuayRepository = "quay.io/mcoqe/layering"
// InternalRegistrySvcURL is the url to reach the internal registry service from inside a cluster
InternalRegistrySvcURL = "image-registry.openshift-image-registry.svc:5000"
// LayeringBaseImageReleaseInfo is the name of the layering base image in release info
LayeringBaseImageReleaseInfo = "rhel-coreos"
// TmplHypershiftMcConfigMap template file name:hypershift-cluster-mc-configmap.yaml, it's used to create mc for hosted cluster
TmplHypershiftMcConfigMap = "hypershift-cluster-mc-configmap.yaml"
// TmplAddSSHAuthorizedKeyForWorker template file name: change-worker-add-ssh-authorized-key
TmplAddSSHAuthorizedKeyForWorker = "change-worker-add-ssh-authorized-key.yaml"
// GenericMCTemplate is the name of a MachineConfig template that can be fully configured by parameters
GenericMCTemplate = "generic-machine-config-template.yml"
// HypershiftCrNodePool keyword: nodepool
HypershiftCrNodePool = "nodepool"
// HypershiftCrHostedCluster keyword: hostedcluster
HypershiftCrHostedCluster = "hostedcluster"
// HypershiftNsClusters namespace: clusters
HypershiftNsClusters = "clusters"
// HypershiftNs operator namespace: hypershift
HypershiftNs = "hypershift"
// HypershiftAwsMachine keyword: awsmachine
HypershiftAwsMachine = "awsmachine"
// NodeAnnotationCurrentConfig current config
NodeAnnotationCurrentConfig = "machineconfiguration.openshift.io/currentConfig"
// NodeAnnotationDesiredConfig desired config
NodeAnnotationDesiredConfig = "machineconfiguration.openshift.io/desiredConfig"
// NodeAnnotationDesiredDrain desired drain id
NodeAnnotationDesiredDrain = "machineconfiguration.openshift.io/desiredDrain"
// NodeAnnotationLastAppliedDrain last applied drain id
NodeAnnotationLastAppliedDrain = "machineconfiguration.openshift.io/lastAppliedDrain"
// NodeAnnotationReason failure reason
NodeAnnotationReason = "machineconfiguration.openshift.io/reason"
// NodeAnnotationState state of the mc
NodeAnnotationState = "machineconfiguration.openshift.io/state"
// TestCtxKeyBucket hypershift test s3 bucket name
TestCtxKeyBucket = "bucket"
// TestCtxKeyNodePool hypershift test node pool name
TestCtxKeyNodePool = "nodepool"
// TestCtxKeyCluster hypershift test hosted cluster name
TestCtxKeyCluster = "cluster"
// TestCtxKeyConfigMap hypershift test config map name
TestCtxKeyConfigMap = "configmap"
// TestCtxKeyKubeConfig hypershift test kubeconfig of hosted cluster
TestCtxKeyKubeConfig = "kubeconfig"
// TestCtxKeyFilePath hypershift test filepath in machine config
TestCtxKeyFilePath = "filepath"
// TestCtxKeySkipCleanUp indicates whether clean up should be skipped
TestCtxKeySkipCleanUp = "skipCleanUp"
// AWSPlatform value used to identify aws infrastructure
AWSPlatform = "aws"
// GCPPlatform value used to identify gcp infrastructure
GCPPlatform = "gcp"
// AzurePlatform value used to identify azure infrastructure
AzurePlatform = "azure"
// NonePlatform value used to identify a None Platform value
NonePlatform = "none"
// BaremetalPlatform value used to identify baremetal infrastructure
BaremetalPlatform = "baremetal"
// KniPlatform value used to identify KNI infrastructure
KniPlatform = "kni"
// NutanixPlatform value used to identify Nutanix infrastructure
NutanixPlatform = "nutanix"
// OpenstackPlatform value used to identify Openstack infrastructure
OpenstackPlatform = "openstack"
// OvirtPlatform value used to identify Ovirt infrastructure
OvirtPlatform = "ovirt"
// VspherePlatform value used to identify Vsphere infrastructure
VspherePlatform = "vsphere"
// AlibabaCloudPlatform value used to identify AlibabaCloud infrastructure
AlibabaCloudPlatform = "alibabacloud"
// ExpirationDockerfileLabel Expiration label in Dockerfile
ExpirationDockerfileLabel = `LABEL maintainer="mco-qe-team" quay.expires-after=24h`
layeringTestsTmpNamespace = "layering-tests-imagestreams"
layeringRegistryAdminSAName = "test-registry-sa"
// DefaultExpectTimeout is the default tiemout for expect commands
DefaultExpectTimeout = 10 * time.Second
// DefaultMinutesWaitingPerNode is the number of minutes per node that the MCPs will wait to become updated
DefaultMinutesWaitingPerNode = 13
// KernelChangeIncWait exta minutes that MCPs will wait per node if we change the kernel in a configuration
KernelChangeIncWait = 5
// ExtensionsChangeIncWait exta minutes that MCPs will wait per node if we change the extensions in a configuration
ExtensionsChangeIncWait = 5
// ImageRegistryCertificatesDir is the path were the image registry certificates will be stored in a node. Example: /etc/docker/certs.d/mycertname/ca.crt
ImageRegistryCertificatesDir = "/etc/docker/certs.d"
// ImageRegistryCertificatesFileName is the name of the image registry certificates. Example: /etc/docker/certs.d/mycertname/ca.crt
ImageRegistryCertificatesFileName = "ca.crt"
// SecurePort is the tls secured port to serve ignition configs
IgnitionSecurePort = 22623
// InsecurePort is the port to serve ignition configs w/o tls
IgnitionInsecurePort = 22624
// Machine phase Provisioning
MachinePhaseProvisioning = "Provisioning"
// Machine phase Deleting
MachinePhaseDeleting = "Deleting"
// We use full name to get machineset/machine xref: https://access.redhat.com/solutions/7040368
// Machineset fully qualified name
MachineSetFullName = "machineset.machine.openshift.io"
// Machine fully qualified name
MachineFullName = "machine.machine.openshift.io"
// TrueString string for true value
TrueString = "True"
// FalseString string for true value
FalseString = "False"
// BusyBoxImage the multiplatform busybox image stored in openshifttest
BusyBoxImage = "quay.io/openshifttest/busybox@sha256:c5439d7db88ab5423999530349d327b04279ad3161d7596d2126dfb5b02bfd1f"
// AlpineImage the multiplatform alpine image stored in openshifttest
AlpineImage = "quay.io/openshifttest/alpine@sha256:dc1536cbff0ba235d4219462aeccd4caceab9def96ae8064257d049166890083"
// TestSSLImage the testssl image stored in openshiftest
TestSSLImage = "quay.io/openshifttest/testssl@sha256:ad6fb8002cb9cfce3ddc8829fd6e7e0d997aeb1faf972650f3e5d7603f90c6ef"
// Constants for NodeDisruptionPolicy
NodeDisruptionPolicyActionNone = "None"
NodeDisruptionPolicyActionReboot = "Reboot"
NodeDisruptionPolicyActionReload = "Reload"
NodeDisruptionPolicyActionRestart = "Restart"
NodeDisruptionPolicyActionDrain = "Drain"
NodeDisruptionPolicyActionDaemonReload = "DaemonReload"
NodeDisruptionPolicyFiles = "files"
NodeDisruptionPolicyUnits = "units"
NodeDisruptionPolicySshkey = "sshkey"
// Regexp used to know if MCD logs is reporting that crio was reloaded
MCDCrioReloadedRegexp = "crio.* reloaded successfully"
// MachineConfigNodesFeature name of the MachineConfigNodes feature
MachineConfigNodesFeature = "MachineConfigNodes"
// MachineConfigServer mcs container name
MachineConfigServer = "machine-config-server"
// TLS Security Version
VersionTLS10 = 0x0301
VersionTLS11 = 0x0302
VersionTLS12 = 0x0303
VersionTLS13 = 0x0304
)
var (
// OnPremPlatforms describes all the on-prem platforms
// xref: https://github.com/openshift/machine-config-operator/blob/752667ba9dfcdefd12222ab422201fa3f9846aca/pkg/controller/template/render.go#L593
OnPremPlatforms = map[string]string{
BaremetalPlatform: "openshift-kni-infra",
NutanixPlatform: "openshift-nutanix-infra",
OpenstackPlatform: "openshift-openstack-infra",
OvirtPlatform: "openshift-ovirt-infra",
VspherePlatform: "openshift-vsphere-infra",
}
)
|
package mco
| ||||
file
|
openshift/openshift-tests-private
|
c49b9d39-fb62-4df7-92bb-885794b574f4
|
gomega_json_matcher
|
import (
"fmt"
logger "github.com/openshift/openshift-tests-private/test/extended/util/logext"
"github.com/tidwall/gjson"
gomegamatchers "github.com/onsi/gomega/matchers"
"github.com/onsi/gomega/types"
)
|
github.com/openshift/openshift-tests-private/test/extended/mco/gomega_json_matcher.go
|
package mco
import (
"fmt"
logger "github.com/openshift/openshift-tests-private/test/extended/util/logext"
"github.com/tidwall/gjson"
gomegamatchers "github.com/onsi/gomega/matchers"
"github.com/onsi/gomega/types"
)
// struct implementing gomaega matcher interface
type gjsonStringMatcher struct {
path string
strData string
expected interface{}
expectedMatcher types.GomegaMatcher
}
// Match checks it the condition matches the given json path. The json information matched is always treated as a string.
func (matcher *gjsonStringMatcher) Match(actual interface{}) (success bool, err error) {
// Check that the checked value is a string
strJSON, ok := actual.(string)
logger.Debugf("Matched JSON: %s", strJSON)
if !ok {
return false, fmt.Errorf(`Wrong type. Matcher expects a type "string": %s`, actual)
}
if !gjson.Valid(strJSON) {
return false, fmt.Errorf(`Wrong format. The string is not a valid JSON: %s`, strJSON)
}
data := gjson.Get(strJSON, matcher.path)
if !data.Exists() {
return false, fmt.Errorf(`The matched path %s does not exist in the provided JSON: %s`, matcher.path, strJSON)
}
matcher.strData = data.String()
// Guess if we provided a value or another matcher in order to check the condition
var isMatcher bool
matcher.expectedMatcher, isMatcher = matcher.expected.(types.GomegaMatcher)
if !isMatcher {
matcher.expectedMatcher = &gomegamatchers.EqualMatcher{Expected: matcher.expected}
}
return matcher.expectedMatcher.Match(matcher.strData)
}
// FailureMessage returns the message when testing `Should` case and `Match` returned false
func (matcher *gjsonStringMatcher) FailureMessage(actual interface{}) (message string) {
// The type was already validated in Match, we can safely ignore the error
strJSON, _ := actual.(string)
message = fmt.Sprintf("%s\n, the matcher was not satisfied by the path %s in json %s",
matcher.expectedMatcher.FailureMessage(matcher.strData), matcher.path, strJSON)
return message
}
// FailureMessage returns the message when testing `ShouldNot` case and `Match` returned true
func (matcher *gjsonStringMatcher) NegatedFailureMessage(actual interface{}) (message string) {
// The type was already validated in Match, we can safely ignore the error
strJSON, _ := actual.(string)
message = fmt.Sprintf("%s\n, the matcher was satisfied (but it should NOT) by the path %s in json %s",
matcher.expectedMatcher.NegatedFailureMessage(matcher.strData), matcher.path, strJSON)
return message
}
// HavePathWithCalue returns the gomega matcher to check if a path in a json data has matches the given condition
func HavePathWithValue(path string, expected interface{}) types.GomegaMatcher {
return &gjsonStringMatcher{path: path, expected: expected}
}
|
package mco
| ||||
function
|
openshift/openshift-tests-private
|
a5fd912e-d759-401c-9781-8841f49099f8
|
Match
|
['"fmt"', '"github.com/tidwall/gjson"', '"github.com/onsi/gomega/types"']
|
['gjsonStringMatcher']
|
github.com/openshift/openshift-tests-private/test/extended/mco/gomega_json_matcher.go
|
func (matcher *gjsonStringMatcher) Match(actual interface{}) (success bool, err error) {
// Check that the checked value is a string
strJSON, ok := actual.(string)
logger.Debugf("Matched JSON: %s", strJSON)
if !ok {
return false, fmt.Errorf(`Wrong type. Matcher expects a type "string": %s`, actual)
}
if !gjson.Valid(strJSON) {
return false, fmt.Errorf(`Wrong format. The string is not a valid JSON: %s`, strJSON)
}
data := gjson.Get(strJSON, matcher.path)
if !data.Exists() {
return false, fmt.Errorf(`The matched path %s does not exist in the provided JSON: %s`, matcher.path, strJSON)
}
matcher.strData = data.String()
// Guess if we provided a value or another matcher in order to check the condition
var isMatcher bool
matcher.expectedMatcher, isMatcher = matcher.expected.(types.GomegaMatcher)
if !isMatcher {
matcher.expectedMatcher = &gomegamatchers.EqualMatcher{Expected: matcher.expected}
}
return matcher.expectedMatcher.Match(matcher.strData)
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
c36329ee-0d7e-4c15-96bf-c64ac0e880c4
|
FailureMessage
|
['"fmt"']
|
['gjsonStringMatcher']
|
github.com/openshift/openshift-tests-private/test/extended/mco/gomega_json_matcher.go
|
func (matcher *gjsonStringMatcher) FailureMessage(actual interface{}) (message string) {
// The type was already validated in Match, we can safely ignore the error
strJSON, _ := actual.(string)
message = fmt.Sprintf("%s\n, the matcher was not satisfied by the path %s in json %s",
matcher.expectedMatcher.FailureMessage(matcher.strData), matcher.path, strJSON)
return message
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
8f721a84-9410-490b-8bf4-66bce9dad85f
|
NegatedFailureMessage
|
['"fmt"']
|
['gjsonStringMatcher']
|
github.com/openshift/openshift-tests-private/test/extended/mco/gomega_json_matcher.go
|
func (matcher *gjsonStringMatcher) NegatedFailureMessage(actual interface{}) (message string) {
// The type was already validated in Match, we can safely ignore the error
strJSON, _ := actual.(string)
message = fmt.Sprintf("%s\n, the matcher was satisfied (but it should NOT) by the path %s in json %s",
matcher.expectedMatcher.NegatedFailureMessage(matcher.strData), matcher.path, strJSON)
return message
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
f4563a0c-5955-464d-8ac2-0ce929798964
|
HavePathWithValue
|
['"github.com/onsi/gomega/types"']
|
['gjsonStringMatcher']
|
github.com/openshift/openshift-tests-private/test/extended/mco/gomega_json_matcher.go
|
func HavePathWithValue(path string, expected interface{}) types.GomegaMatcher {
return &gjsonStringMatcher{path: path, expected: expected}
}
|
mco
| |||
file
|
openshift/openshift-tests-private
|
4145b5fc-346c-4465-a850-34019b19cc71
|
hypershift
|
import (
"bytes"
"fmt"
"os"
"os/exec"
"strconv"
"strings"
o "github.com/onsi/gomega"
exutil "github.com/openshift/openshift-tests-private/test/extended/util"
logger "github.com/openshift/openshift-tests-private/test/extended/util/logext"
)
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
package mco
import (
"bytes"
"fmt"
"os"
"os/exec"
"strconv"
"strings"
o "github.com/onsi/gomega"
exutil "github.com/openshift/openshift-tests-private/test/extended/util"
logger "github.com/openshift/openshift-tests-private/test/extended/util/logext"
)
// HypershiftCli will be used to execute hypershift command e.g. hypershift install etc.
type HypershiftCli struct{}
// CliOptions interface to describe cli option test requirement
type CliOptions interface {
ToArgs() []string
}
// AbstractCliOptions base struct to impl CliOptions
type AbstractCliOptions struct {
options []OptionField
}
// OptionField describe data structure of cli option
type OptionField struct {
name, value string
}
// AwsInstallOptions install option impl for aws
type AwsInstallOptions struct {
AbstractCliOptions
}
// AwsCreateClusterOptions create cluster option impl for aws
type AwsCreateClusterOptions struct {
AbstractCliOptions
}
// AwsDestroyClusterOptions destroy cluster option impl for aws
type AwsDestroyClusterOptions struct {
AbstractCliOptions
}
// AwsCreateNodePoolOptions create node pool option impl for aws
type AwsCreateNodePoolOptions struct {
AbstractCliOptions
}
// ToArgs base class to impl interface of CliOptions
func (bc *AbstractCliOptions) ToArgs() []string {
return bc.transform(bc.options)
}
// appendOption append option with k,v
func (bc *AbstractCliOptions) appendOption(k, v string) {
bc.options = append(
bc.options,
OptionField{
name: k,
value: v,
})
}
// transform the option fields to cli options
func (bc *AbstractCliOptions) transform(options []OptionField) []string {
args := []string{}
for _, field := range options {
if field.value != "" {
args = append(args, field.name, field.value)
} else {
args = append(args, field.name)
}
}
return args
}
// NewAwsInstallOptions constructor of aws install options
func NewAwsInstallOptions() *AwsInstallOptions {
return &AwsInstallOptions{
AbstractCliOptions{
options: []OptionField{},
},
}
}
// WithBucket builder func to append option s3 bucket name
func (opt *AwsInstallOptions) WithBucket(bucket string) *AwsInstallOptions {
opt.appendOption("--oidc-storage-provider-s3-bucket-name", bucket)
return opt
}
// WithCredential builder func to append option s3 cred
func (opt *AwsInstallOptions) WithCredential(cred string) *AwsInstallOptions {
opt.appendOption("--oidc-storage-provider-s3-credentials", cred)
return opt
}
// WithRegion builder func to append option s3 region
func (opt *AwsInstallOptions) WithRegion(region string) *AwsInstallOptions {
opt.appendOption("--oidc-storage-provider-s3-region", region)
return opt
}
// WithNamespace builder func to append option s3 region
func (opt *AwsInstallOptions) WithNamespace(ns string) *AwsInstallOptions {
opt.appendOption("--namespace", ns)
return opt
}
// WithEnableDefaultingWebhook builder func to append option enable-defaulting-webhook
func (opt *AwsInstallOptions) WithEnableDefaultingWebhook() *AwsInstallOptions {
opt.appendOption("--enable-defaulting-webhook", "true")
return opt
}
// WithHypershiftImage builder func to append option enable-defaulting-webhook
func (opt *AwsInstallOptions) WithHypershiftImage(image string) *AwsInstallOptions {
opt.appendOption("--hypershift-image", image)
return opt
}
// NewAwsCreateClusterOptions constructor of create cluster on aws options
func NewAwsCreateClusterOptions() *AwsCreateClusterOptions {
opts := &AwsCreateClusterOptions{
AbstractCliOptions{
options: []OptionField{},
},
}
opts.appendOption("aws", "")
return opts
}
// WithArch builder func to define he arch
func (opt *AwsCreateClusterOptions) WithArch(arch string) *AwsCreateClusterOptions {
opt.appendOption("--arch", arch)
return opt
}
// WithName builder func to append option name
func (opt *AwsCreateClusterOptions) WithName(name string) *AwsCreateClusterOptions {
opt.appendOption("--name", name)
return opt
}
// WithPullSecret builder func to append option pull-secret
func (opt *AwsCreateClusterOptions) WithPullSecret(ps string) *AwsCreateClusterOptions {
opt.appendOption("--pull-secret", ps)
return opt
}
// WithAwsCredential builder func to append option aws-cred
func (opt *AwsCreateClusterOptions) WithAwsCredential(cred string) *AwsCreateClusterOptions {
opt.appendOption("--aws-creds", cred)
return opt
}
// WithBaseDomain builder func to append option base domain
func (opt *AwsCreateClusterOptions) WithBaseDomain(domain string) *AwsCreateClusterOptions {
opt.appendOption("--base-domain", domain)
return opt
}
// WithNodePoolReplica builder func to append option node pool replica
func (opt *AwsCreateClusterOptions) WithNodePoolReplica(replica string) *AwsCreateClusterOptions {
opt.appendOption("--node-pool-replicas", replica)
return opt
}
// WithRegion builder func to append option region
func (opt *AwsCreateClusterOptions) WithRegion(region string) *AwsCreateClusterOptions {
opt.appendOption("--region", region)
return opt
}
// WithReleaseImage builder func to append option release-image
func (opt *AwsCreateClusterOptions) WithReleaseImage(releaseImage string) *AwsCreateClusterOptions {
opt.appendOption("--release-image", releaseImage)
return opt
}
// NewAwsDestroyClusterOptions constructor of destroy cluster on aws options
func NewAwsDestroyClusterOptions() *AwsDestroyClusterOptions {
opts := &AwsDestroyClusterOptions{
AbstractCliOptions{
options: []OptionField{},
},
}
opts.appendOption("aws", "")
return opts
}
// WithName builder func to append option name
func (opt *AwsDestroyClusterOptions) WithName(name string) *AwsDestroyClusterOptions {
opt.appendOption("--name", name)
return opt
}
// WithAwsCredential builder func to append option aws-cred
func (opt *AwsDestroyClusterOptions) WithAwsCredential(cred string) *AwsDestroyClusterOptions {
opt.appendOption("--aws-creds", cred)
return opt
}
// WithDestroyCloudResource builder func to append option destroy cloud resource
func (opt *AwsDestroyClusterOptions) WithDestroyCloudResource() *AwsDestroyClusterOptions {
opt.appendOption("--destroy-cloud-resources", "")
return opt
}
// WithNamespace builder func to append option namespace
func (opt *AwsDestroyClusterOptions) WithNamespace(ns string) *AwsDestroyClusterOptions {
opt.appendOption("--namespace", ns)
return opt
}
// NewAwsCreateNodePoolOptions constructor of create node pool options
func NewAwsCreateNodePoolOptions() *AwsCreateNodePoolOptions {
opts := &AwsCreateNodePoolOptions{
AbstractCliOptions{
options: []OptionField{},
},
}
opts.appendOption("aws", "")
return opts
}
// WithArch builder func to define he arch
func (opt *AwsCreateNodePoolOptions) WithArch(arch string) *AwsCreateNodePoolOptions {
opt.appendOption("--arch", arch)
return opt
}
// WithClusterName builder func to append option cluster
func (opt *AwsCreateNodePoolOptions) WithClusterName(cluster string) *AwsCreateNodePoolOptions {
opt.appendOption("--cluster-name", cluster)
return opt
}
// WithName builder func to append option name
func (opt *AwsCreateNodePoolOptions) WithName(name string) *AwsCreateNodePoolOptions {
opt.appendOption("--name", name)
return opt
}
// WithNodeCount builder func to append option node count
func (opt *AwsCreateNodePoolOptions) WithNodeCount(count string) *AwsCreateNodePoolOptions {
opt.appendOption("--node-count", count)
return opt
}
// WithRender builder func to append option render
func (opt *AwsCreateNodePoolOptions) WithRender() *AwsCreateNodePoolOptions {
opt.appendOption("--render", "")
return opt
}
// WithNamespace builder func to append option namespace
func (opt *AwsCreateNodePoolOptions) WithNamespace(ns string) *AwsCreateNodePoolOptions {
opt.appendOption("--namespace", ns)
return opt
}
// Install install hypershift operator with cli operations
func (hc *HypershiftCli) Install(options CliOptions) (string, error) {
return execHypershift(
append([]string{"install"},
options.ToArgs()...))
}
// Uninstall uninstall hypershift operator from OCP
func (hc *HypershiftCli) Uninstall() (string, error) {
return execBash([]string{
"hypershift install render --format=yaml | oc delete -f -"})
}
// CreateCluster create hosted cluster on different platforms e.g. aws or auzre
func (hc *HypershiftCli) CreateCluster(options CliOptions) (string, error) {
return execHypershift(
append([]string{"create", "cluster"},
options.ToArgs()...))
}
// DestroyCluster destroy hosted cluster with cli options
func (hc *HypershiftCli) DestroyCluster(options CliOptions) (string, error) {
return execHypershift(
append([]string{"destroy", "cluster"},
options.ToArgs()...))
}
// CreateKubeConfig create kubeconfig for hosted cluster
func (hc *HypershiftCli) CreateKubeConfig(clusterName, namespace, filePath string) (string, error) {
return execBash([]string{
fmt.Sprintf("hypershift create kubeconfig --name %s --namespace %s > %s", clusterName, namespace, filePath)})
}
// CreateNodePool create node pool with cli options
func (hc *HypershiftCli) CreateNodePool(options CliOptions) (string, error) {
return execHypershift(
append([]string{"create", "nodepool"},
options.ToArgs()...))
}
// wrapper func to execute hypershift cli
func execHypershift(args []string) (string, error) {
return execCmd("hypershift", args)
}
// wrapper func to execute bash command
func execBash(args []string) (string, error) {
return execCmd(
"bash",
append([]string{"-c"}, args...))
}
// execute cmd, handle std,stderr separately, support debug logging
// if error occurred, log stderr, otherwise return stdout
// tip: hypershift cli redirects some logs to stderr
func execCmd(name string, args []string) (string, error) {
cmd := exec.Command(name, args...)
// handle errbuffer separately
var errbuffer bytes.Buffer
cmd.Stderr = &errbuffer
outbytes, err := cmd.Output()
stdout := string(outbytes)
stderr := string(errbuffer.Bytes())
// print cmdline
logger.Infof("running cmd: %s %s", name, strings.Join(args, " "))
// print debug log for stdout
logger.Debugf("cmd stdout: %s", stdout)
logger.Debugf("cmd stderr: %s", stderr)
if err != nil {
logger.Errorf("cmd exec failed: %v", err)
if cmd.Stderr != nil {
logger.Errorf("cmd stderr: %s", stderr)
}
}
return stdout, err
}
// HypershiftHostedCluster hostedcluster struct, extends resource
type HypershiftHostedCluster struct {
Resource
}
// NewHypershiftHostedCluster constructor of hostedcluster struct
func NewHypershiftHostedCluster(oc *exutil.CLI, clusterNs, name string) *HypershiftHostedCluster {
return &HypershiftHostedCluster{
Resource: *NewNamespacedResource(oc, HypershiftCrHostedCluster, clusterNs, name),
}
}
// GetVersion will return hosted cluster version
func (hc *HypershiftHostedCluster) GetVersion() string {
return hc.GetOrFail(`{.status.version.desired.version}`)
}
// HypershiftNodePool node pool struct, extends resource
type HypershiftNodePool struct {
Resource
}
// NewHypershiftNodePool constructor of node pool struct
func NewHypershiftNodePool(oc *exutil.CLI, clusterNs, name string) *HypershiftNodePool {
return &HypershiftNodePool{
Resource: *NewNamespacedResource(oc, HypershiftCrNodePool, clusterNs, name),
}
}
// IsReady check node pool is ready or not. expected is desired nodes = current nodes
func (np *HypershiftNodePool) IsReady() bool {
logger.Infof("checking nodepool %s is ready", np.name)
// we consider if desired nodes == current nodes, nodepool is ready
desiredNodes := np.GetOrFail("{.spec.replicas}")
currentNodes := np.GetOrFail("{.status.replicas}")
logger.Infof("desired nodes # is %s", desiredNodes)
logger.Infof("current nodes # is %s", currentNodes)
return desiredNodes == currentNodes
}
// WaitUntilReady wait for node pool is ready
func (np *HypershiftNodePool) WaitUntilReady() {
logger.Infof("wait nodepool %s to be ready", np.GetName())
replicas := np.GetOrFail(`{.spec.replicas}`)
o.Eventually(
np.Poll(`{.status.replicas}`),
np.EstimateTimeoutInMins(), "30s").
Should(o.Equal(replicas), "current nodes should equal to desired nodes %s. Nodepool:\n%s", replicas, np.PrettyString())
logger.Infof("nodepool %s is ready", np.GetName())
}
// WaitUntilConfigIsUpdating wait for config update to start
func (np *HypershiftNodePool) WaitUntilConfigIsUpdating() {
logger.Infof("wait condition UpdatingConfig to be true")
o.Eventually(func() map[string]interface{} {
updatingConfig := JSON(np.GetConditionByType("UpdatingConfig"))
if updatingConfig.Exists() {
return updatingConfig.ToMap()
}
logger.Infof("condition UpdatingConfig not found")
return nil
}, "5m", "2s").Should(o.HaveKeyWithValue("status", "True"), "UpdatingConfig condition status should be 'True'. Nodepool:\n%s", np.PrettyString())
logger.Infof("status of condition UpdatingConfig is True")
}
// WaitUntilVersionIsUpdating wait for version update to start
func (np *HypershiftNodePool) WaitUntilVersionIsUpdating() {
logger.Infof("wait condition UpdatingVersion to be true")
o.Eventually(func() map[string]interface{} {
updatingConfig := JSON(np.GetConditionByType("UpdatingVersion"))
if updatingConfig.Exists() {
return updatingConfig.ToMap()
}
logger.Infof("condition UpdatingVersion not found")
return nil
}, "5m", "2s").Should(o.HaveKeyWithValue("status", "True"), "UpdatingVersion condition status should be 'True'. Nodepool:\n%s", np.PrettyString())
logger.Infof("status of condition UpdatingVersion is True")
}
// WaitUntilConfigUpdateIsCompleted poll condition UpdatingConfig until it is disappeared
func (np *HypershiftNodePool) WaitUntilConfigUpdateIsCompleted() {
logger.Infof("wait nodepool %s config update to complete", np.GetName())
o.Eventually(np.GetConditionStatusByType, np.EstimateTimeoutInMins(), "30s").WithArguments("UpdatingConfig").Should(o.Equal("False"),
"config update is not completed. Nodepool:\n%s", np.PrettyString())
logger.Infof("nodepool %s config update is completed", np.GetName())
}
// WaitUntilVersionUpdateIsCompleted poll condition UpdatingVersion until it is disappeared
func (np *HypershiftNodePool) WaitUntilVersionUpdateIsCompleted() {
logger.Infof("wait nodepool %s version update to complete", np.GetName())
o.Eventually(np.GetConditionStatusByType, np.EstimateTimeoutInMins(), "2s").WithArguments("UpdatingVersion").Should(o.Equal("False"),
"version update is not completed. Nodepool:\n%s", np.PrettyString())
logger.Infof("nodepool %s version update is completed", np.GetName())
}
// EstimateTimeoutInMins caculate wait timeout based on replica number
func (np *HypershiftNodePool) EstimateTimeoutInMins() string {
desiredNodes, err := strconv.Atoi(np.GetOrFail(`{.spec.replicas}`))
if err != nil {
desiredNodes = 2 // use 2 replicas as default
}
return fmt.Sprintf("%dm", desiredNodes*15)
}
// GetAllLinuxNodes get all linux nodes in this nodepool
func (np *HypershiftNodePool) GetAllLinuxNodesOrFail() []Node {
workerList := NewNodeList(np.oc.AsAdmin().AsGuestKubeconf())
workerList.ByLabel("kubernetes.io/os=linux,hypershift.openshift.io/nodePool=" + np.GetName())
nodes, getNodesErr := workerList.GetAll()
o.Expect(getNodesErr).NotTo(o.HaveOccurred(), "list all linux nodes in new nodepool error")
o.Expect(nodes).NotTo(o.BeEmpty(), "no linux node found for new nodepool")
return nodes
}
// GetVersion get version of nodepool
func (np *HypershiftNodePool) GetVersion() string {
return np.GetOrFail(`{.status.version}`)
}
// CloudCredential interface to describe test requirement for credential config of cloud platforms
type CloudCredential interface {
OutputToFile(path string) error
}
// AwsCredential AWS impl of CloudCredential
type AwsCredential struct {
accessKey,
secretKey,
region,
profile,
file string
}
// NewAwsCredential constructor of AwsCredential
func NewAwsCredential(oc *exutil.CLI, pf string) (*AwsCredential, error) {
// get aws credential and region from cluster
format := `template={{index .data "%s"|base64decode}}`
// get access key
ak, ake := oc.AsAdmin().WithoutNamespace().Run("get").Args("secrets/aws-creds", "-n", "kube-system", "-o", fmt.Sprintf(format, "aws_access_key_id")).Output()
if ake != nil {
logger.Errorf("get aws access key failed: %v", ake)
return nil, ake
}
// get secret key
sk, ske := oc.AsAdmin().WithoutNamespace().Run("get").Args("secrets/aws-creds", "-n", "kube-system", "-o", fmt.Sprintf(format, "aws_secret_access_key")).Output()
if ske != nil {
logger.Errorf("get aws secret key failed: %v", ske)
return nil, ske
}
// get region
r, re := NewResource(oc.AsAdmin(), "infrastructure", "cluster").Get("{.status.platformStatus.aws.region}")
if re != nil {
logger.Errorf("get aws region failed: %v", re)
return nil, re
}
return &AwsCredential{
accessKey: ak,
secretKey: sk,
region: r,
profile: pf,
}, nil
}
// OutputToFile imple interface CliOptions, save credential info to local config file
func (ac *AwsCredential) OutputToFile(path string) error {
logger.Infof("save aws-cred info to %s", path)
if ac.accessKey == "" || ac.secretKey == "" {
return fmt.Errorf("cannot create aws credential file, accessKey or SecretKey is empty")
}
// if no profile found, [default] profile will be used
if ac.profile == "" {
ac.profile = "default"
}
content := fmt.Sprintf("[%s]\naws_access_key_id = %s\naws_secret_access_key = %s",
ac.profile,
ac.accessKey,
ac.secretKey)
// if the file exists, it will be truncated and permission will not be changed
err := os.WriteFile(path, []byte(content), 0o600)
ac.file = path
return err
}
|
package mco
| ||||
function
|
openshift/openshift-tests-private
|
c9871e84-df29-4e6e-a91f-e7fd91cd95c6
|
ToArgs
|
['AbstractCliOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (bc *AbstractCliOptions) ToArgs() []string {
return bc.transform(bc.options)
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
cacf19c6-3973-4294-9dfa-2be432bb819c
|
appendOption
|
['AbstractCliOptions', 'OptionField']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (bc *AbstractCliOptions) appendOption(k, v string) {
bc.options = append(
bc.options,
OptionField{
name: k,
value: v,
})
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
8efdbe6b-ca34-4f49-924d-25acf81544b4
|
transform
|
['AbstractCliOptions', 'OptionField']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (bc *AbstractCliOptions) transform(options []OptionField) []string {
args := []string{}
for _, field := range options {
if field.value != "" {
args = append(args, field.name, field.value)
} else {
args = append(args, field.name)
}
}
return args
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
89b3a642-ac74-48e2-89f7-f38250210eed
|
NewAwsInstallOptions
|
['AbstractCliOptions', 'OptionField', 'AwsInstallOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func NewAwsInstallOptions() *AwsInstallOptions {
return &AwsInstallOptions{
AbstractCliOptions{
options: []OptionField{},
},
}
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
f98e3a13-d030-406a-81be-879a531a5cab
|
WithBucket
|
['AwsInstallOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsInstallOptions) WithBucket(bucket string) *AwsInstallOptions {
opt.appendOption("--oidc-storage-provider-s3-bucket-name", bucket)
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
e379120a-f1eb-4239-933f-aeb12854eea3
|
WithCredential
|
['AwsInstallOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsInstallOptions) WithCredential(cred string) *AwsInstallOptions {
opt.appendOption("--oidc-storage-provider-s3-credentials", cred)
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
3dfbab4f-b933-4a38-9c0b-7c6c7f019d77
|
WithRegion
|
['AwsInstallOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsInstallOptions) WithRegion(region string) *AwsInstallOptions {
opt.appendOption("--oidc-storage-provider-s3-region", region)
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
1284c62c-6c43-4005-87ef-4933687a4956
|
WithNamespace
|
['AwsInstallOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsInstallOptions) WithNamespace(ns string) *AwsInstallOptions {
opt.appendOption("--namespace", ns)
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
d6457e24-d2d0-4058-a9a8-681535e915c8
|
WithEnableDefaultingWebhook
|
['AwsInstallOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsInstallOptions) WithEnableDefaultingWebhook() *AwsInstallOptions {
opt.appendOption("--enable-defaulting-webhook", "true")
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
dfaf25c6-1e30-41cd-b1f8-aa7af3df0949
|
WithHypershiftImage
|
['AwsInstallOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsInstallOptions) WithHypershiftImage(image string) *AwsInstallOptions {
opt.appendOption("--hypershift-image", image)
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
c17203bd-30df-41c7-95ff-255d45c00f67
|
NewAwsCreateClusterOptions
|
['AbstractCliOptions', 'OptionField', 'AwsCreateClusterOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func NewAwsCreateClusterOptions() *AwsCreateClusterOptions {
opts := &AwsCreateClusterOptions{
AbstractCliOptions{
options: []OptionField{},
},
}
opts.appendOption("aws", "")
return opts
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
0d0aa59d-1750-44c7-b2a5-200965dba614
|
WithArch
|
['AwsCreateClusterOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsCreateClusterOptions) WithArch(arch string) *AwsCreateClusterOptions {
opt.appendOption("--arch", arch)
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
18d881d7-8caf-4b72-a59a-c84ba60fefad
|
WithName
|
['AwsCreateClusterOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsCreateClusterOptions) WithName(name string) *AwsCreateClusterOptions {
opt.appendOption("--name", name)
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
cd41f862-b97c-4818-9803-fa209c4beb8b
|
WithPullSecret
|
['AwsCreateClusterOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsCreateClusterOptions) WithPullSecret(ps string) *AwsCreateClusterOptions {
opt.appendOption("--pull-secret", ps)
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
76a90d98-eb41-4639-b269-4890af4e0536
|
WithAwsCredential
|
['AwsCreateClusterOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsCreateClusterOptions) WithAwsCredential(cred string) *AwsCreateClusterOptions {
opt.appendOption("--aws-creds", cred)
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
2b35d869-5ff3-4057-9991-181f6e91e34b
|
WithBaseDomain
|
['AwsCreateClusterOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsCreateClusterOptions) WithBaseDomain(domain string) *AwsCreateClusterOptions {
opt.appendOption("--base-domain", domain)
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
922d3870-da82-4f9c-989a-ee010b646968
|
WithNodePoolReplica
|
['AwsCreateClusterOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsCreateClusterOptions) WithNodePoolReplica(replica string) *AwsCreateClusterOptions {
opt.appendOption("--node-pool-replicas", replica)
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
618e7125-6619-43ef-8de4-8ba1aaa7abcc
|
WithRegion
|
['AwsCreateClusterOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsCreateClusterOptions) WithRegion(region string) *AwsCreateClusterOptions {
opt.appendOption("--region", region)
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
870b5557-bc7b-476d-9df4-1bdc37e5283b
|
WithReleaseImage
|
['AwsCreateClusterOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsCreateClusterOptions) WithReleaseImage(releaseImage string) *AwsCreateClusterOptions {
opt.appendOption("--release-image", releaseImage)
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
90e1e391-c005-42e4-8991-d320c032b041
|
NewAwsDestroyClusterOptions
|
['AbstractCliOptions', 'OptionField', 'AwsDestroyClusterOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func NewAwsDestroyClusterOptions() *AwsDestroyClusterOptions {
opts := &AwsDestroyClusterOptions{
AbstractCliOptions{
options: []OptionField{},
},
}
opts.appendOption("aws", "")
return opts
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
ece27aa5-602e-45dc-bb0a-f64274621504
|
WithName
|
['AwsDestroyClusterOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsDestroyClusterOptions) WithName(name string) *AwsDestroyClusterOptions {
opt.appendOption("--name", name)
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
78d86f02-375b-4754-8a74-1f0d58080392
|
WithAwsCredential
|
['AwsDestroyClusterOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsDestroyClusterOptions) WithAwsCredential(cred string) *AwsDestroyClusterOptions {
opt.appendOption("--aws-creds", cred)
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
0da6dfbc-4b4c-4766-b8dc-3bcca1c7214c
|
WithDestroyCloudResource
|
['AwsDestroyClusterOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsDestroyClusterOptions) WithDestroyCloudResource() *AwsDestroyClusterOptions {
opt.appendOption("--destroy-cloud-resources", "")
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
73ec5cc3-7624-4512-9e88-3ac9ca76527f
|
WithNamespace
|
['AwsDestroyClusterOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsDestroyClusterOptions) WithNamespace(ns string) *AwsDestroyClusterOptions {
opt.appendOption("--namespace", ns)
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
b65771e3-a449-476c-9b11-029296e18b90
|
NewAwsCreateNodePoolOptions
|
['AbstractCliOptions', 'OptionField', 'AwsCreateNodePoolOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func NewAwsCreateNodePoolOptions() *AwsCreateNodePoolOptions {
opts := &AwsCreateNodePoolOptions{
AbstractCliOptions{
options: []OptionField{},
},
}
opts.appendOption("aws", "")
return opts
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
8c2dc731-b576-47dc-9691-acad142d9a06
|
WithArch
|
['AwsCreateNodePoolOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsCreateNodePoolOptions) WithArch(arch string) *AwsCreateNodePoolOptions {
opt.appendOption("--arch", arch)
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
3429eb10-e500-4f42-bb2f-4648a2ebc904
|
WithClusterName
|
['AwsCreateNodePoolOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsCreateNodePoolOptions) WithClusterName(cluster string) *AwsCreateNodePoolOptions {
opt.appendOption("--cluster-name", cluster)
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
7833458f-81cd-4a91-b676-c41f29ef7fbf
|
WithName
|
['AwsCreateNodePoolOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsCreateNodePoolOptions) WithName(name string) *AwsCreateNodePoolOptions {
opt.appendOption("--name", name)
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
1ecb3100-a214-45ec-b51e-4f9e635359aa
|
WithNodeCount
|
['AwsCreateNodePoolOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsCreateNodePoolOptions) WithNodeCount(count string) *AwsCreateNodePoolOptions {
opt.appendOption("--node-count", count)
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
09560ca8-5f25-4ab8-9094-2a4de9eefba1
|
WithRender
|
['AwsCreateNodePoolOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsCreateNodePoolOptions) WithRender() *AwsCreateNodePoolOptions {
opt.appendOption("--render", "")
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
848456f1-078d-4f87-804d-ad72fe542805
|
WithNamespace
|
['AwsCreateNodePoolOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (opt *AwsCreateNodePoolOptions) WithNamespace(ns string) *AwsCreateNodePoolOptions {
opt.appendOption("--namespace", ns)
return opt
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
e1bd0723-6481-43eb-81e4-c001e82640f1
|
Install
|
['HypershiftCli']
|
['CliOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (hc *HypershiftCli) Install(options CliOptions) (string, error) {
return execHypershift(
append([]string{"install"},
options.ToArgs()...))
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
b1226083-62f7-4e1a-83f3-729e1b1a296f
|
Uninstall
|
['HypershiftCli']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (hc *HypershiftCli) Uninstall() (string, error) {
return execBash([]string{
"hypershift install render --format=yaml | oc delete -f -"})
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
d0190639-bef8-42b9-92ff-7eeadd183dbc
|
CreateCluster
|
['HypershiftCli']
|
['CliOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (hc *HypershiftCli) CreateCluster(options CliOptions) (string, error) {
return execHypershift(
append([]string{"create", "cluster"},
options.ToArgs()...))
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
333e1f77-4946-4ef8-87d0-8d7a8259f302
|
DestroyCluster
|
['HypershiftCli']
|
['CliOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (hc *HypershiftCli) DestroyCluster(options CliOptions) (string, error) {
return execHypershift(
append([]string{"destroy", "cluster"},
options.ToArgs()...))
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
9bd83871-82f6-4d2b-b3ed-15d7c3a8ac1f
|
CreateKubeConfig
|
['"fmt"']
|
['HypershiftCli']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (hc *HypershiftCli) CreateKubeConfig(clusterName, namespace, filePath string) (string, error) {
return execBash([]string{
fmt.Sprintf("hypershift create kubeconfig --name %s --namespace %s > %s", clusterName, namespace, filePath)})
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
7afef7b2-7376-4d02-aa68-9a3df91002dd
|
CreateNodePool
|
['HypershiftCli']
|
['CliOptions']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (hc *HypershiftCli) CreateNodePool(options CliOptions) (string, error) {
return execHypershift(
append([]string{"create", "nodepool"},
options.ToArgs()...))
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
0e86e987-7361-4cca-9b74-81b39d3af0ec
|
execHypershift
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func execHypershift(args []string) (string, error) {
return execCmd("hypershift", args)
}
|
mco
| |||||
function
|
openshift/openshift-tests-private
|
e89d5542-bdca-4dc3-a7d2-8bcb960dadd6
|
execBash
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func execBash(args []string) (string, error) {
return execCmd(
"bash",
append([]string{"-c"}, args...))
}
|
mco
| |||||
function
|
openshift/openshift-tests-private
|
0ea3c6a6-b713-4d0f-b416-5aadb78c1d1c
|
execCmd
|
['"bytes"', '"os/exec"', '"strings"']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func execCmd(name string, args []string) (string, error) {
cmd := exec.Command(name, args...)
// handle errbuffer separately
var errbuffer bytes.Buffer
cmd.Stderr = &errbuffer
outbytes, err := cmd.Output()
stdout := string(outbytes)
stderr := string(errbuffer.Bytes())
// print cmdline
logger.Infof("running cmd: %s %s", name, strings.Join(args, " "))
// print debug log for stdout
logger.Debugf("cmd stdout: %s", stdout)
logger.Debugf("cmd stderr: %s", stderr)
if err != nil {
logger.Errorf("cmd exec failed: %v", err)
if cmd.Stderr != nil {
logger.Errorf("cmd stderr: %s", stderr)
}
}
return stdout, err
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
89341bf9-e9ba-41df-bbd5-df90d742fe02
|
NewHypershiftHostedCluster
|
['HypershiftHostedCluster']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func NewHypershiftHostedCluster(oc *exutil.CLI, clusterNs, name string) *HypershiftHostedCluster {
return &HypershiftHostedCluster{
Resource: *NewNamespacedResource(oc, HypershiftCrHostedCluster, clusterNs, name),
}
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
3568f2b8-aa88-423d-8ffa-dd25f0d58918
|
GetVersion
|
['HypershiftHostedCluster']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (hc *HypershiftHostedCluster) GetVersion() string {
return hc.GetOrFail(`{.status.version.desired.version}`)
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
ccca3e95-37af-414d-88a6-635062a138ce
|
NewHypershiftNodePool
|
['HypershiftNodePool']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func NewHypershiftNodePool(oc *exutil.CLI, clusterNs, name string) *HypershiftNodePool {
return &HypershiftNodePool{
Resource: *NewNamespacedResource(oc, HypershiftCrNodePool, clusterNs, name),
}
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
62c31319-c7c7-4766-bf2d-030f4bff7985
|
IsReady
|
['HypershiftNodePool']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (np *HypershiftNodePool) IsReady() bool {
logger.Infof("checking nodepool %s is ready", np.name)
// we consider if desired nodes == current nodes, nodepool is ready
desiredNodes := np.GetOrFail("{.spec.replicas}")
currentNodes := np.GetOrFail("{.status.replicas}")
logger.Infof("desired nodes # is %s", desiredNodes)
logger.Infof("current nodes # is %s", currentNodes)
return desiredNodes == currentNodes
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
f546097e-bdf2-4e06-a01d-603c635c5655
|
WaitUntilReady
|
['HypershiftNodePool']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (np *HypershiftNodePool) WaitUntilReady() {
logger.Infof("wait nodepool %s to be ready", np.GetName())
replicas := np.GetOrFail(`{.spec.replicas}`)
o.Eventually(
np.Poll(`{.status.replicas}`),
np.EstimateTimeoutInMins(), "30s").
Should(o.Equal(replicas), "current nodes should equal to desired nodes %s. Nodepool:\n%s", replicas, np.PrettyString())
logger.Infof("nodepool %s is ready", np.GetName())
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
ab3fee18-a6eb-4b14-80c4-5bbde6e4df0b
|
WaitUntilConfigIsUpdating
|
['HypershiftNodePool']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (np *HypershiftNodePool) WaitUntilConfigIsUpdating() {
logger.Infof("wait condition UpdatingConfig to be true")
o.Eventually(func() map[string]interface{} {
updatingConfig := JSON(np.GetConditionByType("UpdatingConfig"))
if updatingConfig.Exists() {
return updatingConfig.ToMap()
}
logger.Infof("condition UpdatingConfig not found")
return nil
}, "5m", "2s").Should(o.HaveKeyWithValue("status", "True"), "UpdatingConfig condition status should be 'True'. Nodepool:\n%s", np.PrettyString())
logger.Infof("status of condition UpdatingConfig is True")
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
3c5a1adc-1400-4bcb-847b-513ec81ed5bb
|
WaitUntilVersionIsUpdating
|
['HypershiftNodePool']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (np *HypershiftNodePool) WaitUntilVersionIsUpdating() {
logger.Infof("wait condition UpdatingVersion to be true")
o.Eventually(func() map[string]interface{} {
updatingConfig := JSON(np.GetConditionByType("UpdatingVersion"))
if updatingConfig.Exists() {
return updatingConfig.ToMap()
}
logger.Infof("condition UpdatingVersion not found")
return nil
}, "5m", "2s").Should(o.HaveKeyWithValue("status", "True"), "UpdatingVersion condition status should be 'True'. Nodepool:\n%s", np.PrettyString())
logger.Infof("status of condition UpdatingVersion is True")
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
3614c2f4-ce10-4b67-a5a2-7ca7d6e736b9
|
WaitUntilConfigUpdateIsCompleted
|
['HypershiftNodePool']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (np *HypershiftNodePool) WaitUntilConfigUpdateIsCompleted() {
logger.Infof("wait nodepool %s config update to complete", np.GetName())
o.Eventually(np.GetConditionStatusByType, np.EstimateTimeoutInMins(), "30s").WithArguments("UpdatingConfig").Should(o.Equal("False"),
"config update is not completed. Nodepool:\n%s", np.PrettyString())
logger.Infof("nodepool %s config update is completed", np.GetName())
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
858bf5b7-1515-47cd-b121-f1add73d0b47
|
WaitUntilVersionUpdateIsCompleted
|
['HypershiftNodePool']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (np *HypershiftNodePool) WaitUntilVersionUpdateIsCompleted() {
logger.Infof("wait nodepool %s version update to complete", np.GetName())
o.Eventually(np.GetConditionStatusByType, np.EstimateTimeoutInMins(), "2s").WithArguments("UpdatingVersion").Should(o.Equal("False"),
"version update is not completed. Nodepool:\n%s", np.PrettyString())
logger.Infof("nodepool %s version update is completed", np.GetName())
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
7f57292a-f9b0-4c8f-82c5-9568aa100d00
|
EstimateTimeoutInMins
|
['"fmt"', '"strconv"']
|
['HypershiftNodePool']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (np *HypershiftNodePool) EstimateTimeoutInMins() string {
desiredNodes, err := strconv.Atoi(np.GetOrFail(`{.spec.replicas}`))
if err != nil {
desiredNodes = 2 // use 2 replicas as default
}
return fmt.Sprintf("%dm", desiredNodes*15)
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
cc7176cf-8a1a-4f23-bd7c-81d85fa79188
|
GetAllLinuxNodesOrFail
|
['"os"']
|
['HypershiftNodePool']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (np *HypershiftNodePool) GetAllLinuxNodesOrFail() []Node {
workerList := NewNodeList(np.oc.AsAdmin().AsGuestKubeconf())
workerList.ByLabel("kubernetes.io/os=linux,hypershift.openshift.io/nodePool=" + np.GetName())
nodes, getNodesErr := workerList.GetAll()
o.Expect(getNodesErr).NotTo(o.HaveOccurred(), "list all linux nodes in new nodepool error")
o.Expect(nodes).NotTo(o.BeEmpty(), "no linux node found for new nodepool")
return nodes
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
6a640f24-5633-476b-bcf1-351c80f6375c
|
GetVersion
|
['HypershiftNodePool']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (np *HypershiftNodePool) GetVersion() string {
return np.GetOrFail(`{.status.version}`)
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
6a8cccb1-6768-470c-912e-f53a0fbbb469
|
NewAwsCredential
|
['"fmt"']
|
['AwsCredential']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func NewAwsCredential(oc *exutil.CLI, pf string) (*AwsCredential, error) {
// get aws credential and region from cluster
format := `template={{index .data "%s"|base64decode}}`
// get access key
ak, ake := oc.AsAdmin().WithoutNamespace().Run("get").Args("secrets/aws-creds", "-n", "kube-system", "-o", fmt.Sprintf(format, "aws_access_key_id")).Output()
if ake != nil {
logger.Errorf("get aws access key failed: %v", ake)
return nil, ake
}
// get secret key
sk, ske := oc.AsAdmin().WithoutNamespace().Run("get").Args("secrets/aws-creds", "-n", "kube-system", "-o", fmt.Sprintf(format, "aws_secret_access_key")).Output()
if ske != nil {
logger.Errorf("get aws secret key failed: %v", ske)
return nil, ske
}
// get region
r, re := NewResource(oc.AsAdmin(), "infrastructure", "cluster").Get("{.status.platformStatus.aws.region}")
if re != nil {
logger.Errorf("get aws region failed: %v", re)
return nil, re
}
return &AwsCredential{
accessKey: ak,
secretKey: sk,
region: r,
profile: pf,
}, nil
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
a5f43763-fb37-4545-b086-289396257044
|
OutputToFile
|
['"fmt"', '"os"']
|
['AwsCredential']
|
github.com/openshift/openshift-tests-private/test/extended/mco/hypershift.go
|
func (ac *AwsCredential) OutputToFile(path string) error {
logger.Infof("save aws-cred info to %s", path)
if ac.accessKey == "" || ac.secretKey == "" {
return fmt.Errorf("cannot create aws credential file, accessKey or SecretKey is empty")
}
// if no profile found, [default] profile will be used
if ac.profile == "" {
ac.profile = "default"
}
content := fmt.Sprintf("[%s]\naws_access_key_id = %s\naws_secret_access_key = %s",
ac.profile,
ac.accessKey,
ac.secretKey)
// if the file exists, it will be truncated and permission will not be changed
err := os.WriteFile(path, []byte(content), 0o600)
ac.file = path
return err
}
|
mco
| |||
file
|
openshift/openshift-tests-private
|
d85e1d00-116d-4c16-b911-7fb5fbc4e8e4
|
jsondata
|
import (
"encoding/json"
"fmt"
"strings"
logger "github.com/openshift/openshift-tests-private/test/extended/util/logext"
"k8s.io/client-go/util/jsonpath"
e2e "k8s.io/kubernetes/test/e2e/framework"
)
|
github.com/openshift/openshift-tests-private/test/extended/mco/jsondata.go
|
package mco
import (
"encoding/json"
"fmt"
"strings"
logger "github.com/openshift/openshift-tests-private/test/extended/util/logext"
"k8s.io/client-go/util/jsonpath"
e2e "k8s.io/kubernetes/test/e2e/framework"
)
// JSON function creates a JSONData struct from a string with json format
func JSON(jsonString string) *JSONData {
jsonData := JSONData{nil}
if strings.Trim(jsonString, " ") == "" {
return &jsonData
}
if err := json.Unmarshal([]byte(jsonString), &jsonData.data); err != nil {
logger.Errorf("Data is not in json format:\n %s", jsonString)
return nil
}
return &jsonData
}
// JSONData provides the functionliaty to manipulate data in json format
type JSONData struct {
data interface{}
}
// AsJSONString returns a JSON string representation fo the stored value
func (jd *JSONData) AsJSONString() (string, error) {
text, err := json.MarshalIndent(jd.data, "", " ")
return string(text), err
}
// ToFloat returns the stored value as float64
func (jd *JSONData) ToFloat() float64 {
return jd.data.(float64)
}
// ToInt returns the stored value as Int. If float, it will be transformed to Int
func (jd *JSONData) ToInt() int {
return int(jd.data.(float64))
}
// ToBool returns the stored value as bool.
func (jd *JSONData) ToBool() bool {
return jd.data.(bool)
}
// ToString returns the stored value as string
func (jd *JSONData) ToString() string {
return jd.data.(string)
}
// ToMap returns the stored value as map[string]interface{}
func (jd *JSONData) ToMap() map[string]interface{} {
return jd.data.(map[string]interface{})
}
// ToList returns the stored value as []interface{}
func (jd *JSONData) ToList() []interface{} {
return jd.data.([]interface{})
}
// ToInterface returns the raw stored value
func (jd *JSONData) ToInterface() interface{} {
return jd.data
}
// Exists is true if the stored value is not nil
func (jd *JSONData) Exists() bool {
return jd.data != nil
}
// String implements the stringer interface
func (jd *JSONData) String() string {
result, err := jd.AsJSONString()
if err != nil {
return fmt.Sprintf("%v", jd.data)
}
return result
}
// DeleteSafe deletes a key in a map json node
func (jd *JSONData) DeleteSafe(key string) error {
if jd.data == nil {
return fmt.Errorf("Data does not exist. It is empty: %v", jd.data)
}
mapData, ok := jd.data.(map[string]interface{})
if !ok {
return fmt.Errorf("Data is not a map: %v", jd.data)
}
delete(mapData, key)
return nil
}
// Delete deletes the a key in a map json node
func (jd *JSONData) Delete(key string) {
err := jd.DeleteSafe(key)
if err != nil {
e2e.Failf("Could not DELETE key [%s] from json data [%s]. Error: %v", key, jd.data, err)
}
}
// PutSafe set the value of a key in a map json node
func (jd *JSONData) PutSafe(key string, value interface{}) error {
if jd.data == nil {
return fmt.Errorf("Data does not exist. It is empty: %v", jd.data)
}
mapData, ok := jd.data.(map[string]interface{})
if !ok {
return fmt.Errorf("Data is not a map: %v", jd.data)
}
mapData[key] = value
return nil
}
// Put sets the value of a key in a map json node
func (jd *JSONData) Put(key, value string) {
err := jd.PutSafe(key, value)
if err != nil {
e2e.Failf("Could not PUT key [%s] value [%s] in json data [%s]. Error: %v", key, value, jd.data, err)
}
}
// GetSafe returns the value of a key in the data and an error
func (jd JSONData) GetSafe(key string) (*JSONData, error) {
if jd.data == nil {
return nil, fmt.Errorf("Data does not exist. It is empty: %v", jd.data)
}
mapData, ok := jd.data.(map[string]interface{})
if !ok {
return nil, fmt.Errorf("Data is not a map: %v", jd.data)
}
value, found := mapData[key]
if found {
return &JSONData{value}, nil
}
return &JSONData{nil}, nil
}
// ItemSafe returns the value of a given item in a list and an error
func (jd JSONData) ItemSafe(index int) (*JSONData, error) {
if jd.data == nil {
return nil, fmt.Errorf("Data does not exist. It is empty: %v", jd.data)
}
listData, ok := jd.data.([]interface{})
if !ok {
return nil, fmt.Errorf("Data is not a list: %v", jd.data)
}
return &JSONData{listData[index]}, nil
}
// Get returns the value of a key in the data, in case of error the returned value is nil
func (jd JSONData) Get(key string) *JSONData {
value, err := jd.GetSafe(key)
if err != nil {
e2e.Failf("Could not get key [%s]. Error: %v", key, err)
}
return value
}
// Item returns the value of a given item in a list, in case of error the returned value is nil
func (jd JSONData) Item(index int) *JSONData {
value, err := jd.ItemSafe(index)
if err != nil {
e2e.Failf("Could not get item [%d]. Error: %v", index, err)
}
return value
}
// Items returns all values in a list as JSONData structs.
func (jd JSONData) Items() []*JSONData {
if jd.data == nil {
e2e.Failf("Data does not exist. It is empty: %v", jd.data)
}
listData, ok := jd.data.([]interface{})
if !ok {
e2e.Failf("Data is not a list: %v", jd.data)
}
ret := []*JSONData{}
for _, data := range listData {
ret = append(ret, &JSONData{data})
}
return ret
}
// GetRawValue will return the jsonPath output as it is, without any kind of flattening or property transformation
func (jd *JSONData) GetRawValue(jsonPath string) ([]interface{}, error) {
j := jsonpath.New("parser: " + jsonPath)
if err := j.Parse(jsonPath); err != nil {
return nil, err
}
fullResults, err := j.FindResults(jd.data)
if err != nil {
return nil, err
}
returnResults := make([]interface{}, 0, len(fullResults))
for _, result := range fullResults {
res := make([]interface{}, 0, len(result))
for i := range result {
res = append(res, result[i].Interface())
}
returnResults = append(returnResults, res)
}
return returnResults, nil
}
// GetJSONPath will return a flattened list of JSONData structs with the values matching the jsonpath expression
func (jd *JSONData) GetJSONPath(jsonPath string) ([]JSONData, error) {
allResults, err := jd.GetRawValue(jsonPath)
if err != nil {
return nil, err
}
flatResults := flattenResults(allResults)
return flatResults, err
}
func flattenResults(allExpresults []interface{}) []JSONData {
flatResults := []JSONData{}
for i := range allExpresults {
var expression = allExpresults[i].([]interface{})
for _, result := range expression {
flatResults = append(flatResults, JSONData{result})
}
}
return flatResults
}
|
package mco
| ||||
function
|
openshift/openshift-tests-private
|
4eb8acf8-2314-466b-8f2e-52932ff78513
|
JSON
|
['"encoding/json"', '"strings"']
|
['JSONData']
|
github.com/openshift/openshift-tests-private/test/extended/mco/jsondata.go
|
func JSON(jsonString string) *JSONData {
jsonData := JSONData{nil}
if strings.Trim(jsonString, " ") == "" {
return &jsonData
}
if err := json.Unmarshal([]byte(jsonString), &jsonData.data); err != nil {
logger.Errorf("Data is not in json format:\n %s", jsonString)
return nil
}
return &jsonData
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
c12e94ee-74ca-45c9-aaaa-85684f8de0f3
|
AsJSONString
|
['"encoding/json"']
|
['JSONData']
|
github.com/openshift/openshift-tests-private/test/extended/mco/jsondata.go
|
func (jd *JSONData) AsJSONString() (string, error) {
text, err := json.MarshalIndent(jd.data, "", " ")
return string(text), err
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
c37f6d61-c474-4c8e-800c-8322a37b1232
|
ToFloat
|
['JSONData']
|
github.com/openshift/openshift-tests-private/test/extended/mco/jsondata.go
|
func (jd *JSONData) ToFloat() float64 {
return jd.data.(float64)
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
c688ff7a-9232-49e5-9d87-01a0b34bcdae
|
ToInt
|
['JSONData']
|
github.com/openshift/openshift-tests-private/test/extended/mco/jsondata.go
|
func (jd *JSONData) ToInt() int {
return int(jd.data.(float64))
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
2516327b-1f3b-48d6-8e4b-3c90de1eb3b8
|
ToBool
|
['JSONData']
|
github.com/openshift/openshift-tests-private/test/extended/mco/jsondata.go
|
func (jd *JSONData) ToBool() bool {
return jd.data.(bool)
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
275e21f0-3ba9-44bc-b1ae-c6604fb93472
|
ToString
|
['JSONData']
|
github.com/openshift/openshift-tests-private/test/extended/mco/jsondata.go
|
func (jd *JSONData) ToString() string {
return jd.data.(string)
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
667dc026-f63d-42db-99c7-1cad48eac008
|
ToMap
|
['JSONData']
|
github.com/openshift/openshift-tests-private/test/extended/mco/jsondata.go
|
func (jd *JSONData) ToMap() map[string]interface{} {
return jd.data.(map[string]interface{})
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
96cfe4cf-a54e-4c58-9b51-3462c6270641
|
ToList
|
['JSONData']
|
github.com/openshift/openshift-tests-private/test/extended/mco/jsondata.go
|
func (jd *JSONData) ToList() []interface{} {
return jd.data.([]interface{})
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
3895fce7-998f-44c6-89f8-4a456130fb17
|
ToInterface
|
['JSONData']
|
github.com/openshift/openshift-tests-private/test/extended/mco/jsondata.go
|
func (jd *JSONData) ToInterface() interface{} {
return jd.data
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
beb1f620-683f-402c-af05-b3991b52d094
|
Exists
|
['JSONData']
|
github.com/openshift/openshift-tests-private/test/extended/mco/jsondata.go
|
func (jd *JSONData) Exists() bool {
return jd.data != nil
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
99371314-d832-4238-a8fe-4340c694c557
|
String
|
['"fmt"']
|
['JSONData']
|
github.com/openshift/openshift-tests-private/test/extended/mco/jsondata.go
|
func (jd *JSONData) String() string {
result, err := jd.AsJSONString()
if err != nil {
return fmt.Sprintf("%v", jd.data)
}
return result
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
e70ceb19-5709-4611-9027-cb609024dcda
|
DeleteSafe
|
['"fmt"']
|
['JSONData']
|
github.com/openshift/openshift-tests-private/test/extended/mco/jsondata.go
|
func (jd *JSONData) DeleteSafe(key string) error {
if jd.data == nil {
return fmt.Errorf("Data does not exist. It is empty: %v", jd.data)
}
mapData, ok := jd.data.(map[string]interface{})
if !ok {
return fmt.Errorf("Data is not a map: %v", jd.data)
}
delete(mapData, key)
return nil
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
df4e0482-18bb-4abf-96b4-897b59a7de1c
|
Delete
|
['"encoding/json"']
|
['JSONData']
|
github.com/openshift/openshift-tests-private/test/extended/mco/jsondata.go
|
func (jd *JSONData) Delete(key string) {
err := jd.DeleteSafe(key)
if err != nil {
e2e.Failf("Could not DELETE key [%s] from json data [%s]. Error: %v", key, jd.data, err)
}
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
fa9aca71-558e-43f0-9dda-8eab59ac0974
|
PutSafe
|
['"fmt"']
|
['JSONData']
|
github.com/openshift/openshift-tests-private/test/extended/mco/jsondata.go
|
func (jd *JSONData) PutSafe(key string, value interface{}) error {
if jd.data == nil {
return fmt.Errorf("Data does not exist. It is empty: %v", jd.data)
}
mapData, ok := jd.data.(map[string]interface{})
if !ok {
return fmt.Errorf("Data is not a map: %v", jd.data)
}
mapData[key] = value
return nil
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
054bea9e-6f58-4b03-a100-d12b89b066bb
|
Put
|
['"encoding/json"']
|
['JSONData']
|
github.com/openshift/openshift-tests-private/test/extended/mco/jsondata.go
|
func (jd *JSONData) Put(key, value string) {
err := jd.PutSafe(key, value)
if err != nil {
e2e.Failf("Could not PUT key [%s] value [%s] in json data [%s]. Error: %v", key, value, jd.data, err)
}
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
9f2a2897-1cf4-491f-9fbe-989ccaff849e
|
GetSafe
|
['"fmt"']
|
['JSONData']
|
github.com/openshift/openshift-tests-private/test/extended/mco/jsondata.go
|
func (jd JSONData) GetSafe(key string) (*JSONData, error) {
if jd.data == nil {
return nil, fmt.Errorf("Data does not exist. It is empty: %v", jd.data)
}
mapData, ok := jd.data.(map[string]interface{})
if !ok {
return nil, fmt.Errorf("Data is not a map: %v", jd.data)
}
value, found := mapData[key]
if found {
return &JSONData{value}, nil
}
return &JSONData{nil}, nil
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
bddab505-2e5d-4ef4-a435-2465367b3577
|
ItemSafe
|
['"fmt"']
|
['JSONData']
|
github.com/openshift/openshift-tests-private/test/extended/mco/jsondata.go
|
func (jd JSONData) ItemSafe(index int) (*JSONData, error) {
if jd.data == nil {
return nil, fmt.Errorf("Data does not exist. It is empty: %v", jd.data)
}
listData, ok := jd.data.([]interface{})
if !ok {
return nil, fmt.Errorf("Data is not a list: %v", jd.data)
}
return &JSONData{listData[index]}, nil
}
|
mco
| |||
function
|
openshift/openshift-tests-private
|
12aae694-0831-42d9-99f5-61c8d51b500b
|
Get
|
['JSONData']
|
github.com/openshift/openshift-tests-private/test/extended/mco/jsondata.go
|
func (jd JSONData) Get(key string) *JSONData {
value, err := jd.GetSafe(key)
if err != nil {
e2e.Failf("Could not get key [%s]. Error: %v", key, err)
}
return value
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
c03fdbbe-d251-4fb9-b6f3-b22c8600c697
|
Item
|
['JSONData']
|
github.com/openshift/openshift-tests-private/test/extended/mco/jsondata.go
|
func (jd JSONData) Item(index int) *JSONData {
value, err := jd.ItemSafe(index)
if err != nil {
e2e.Failf("Could not get item [%d]. Error: %v", index, err)
}
return value
}
|
mco
| ||||
function
|
openshift/openshift-tests-private
|
80465942-3ca3-4fcb-a756-bfa3cd7608b4
|
Items
|
['JSONData']
|
github.com/openshift/openshift-tests-private/test/extended/mco/jsondata.go
|
func (jd JSONData) Items() []*JSONData {
if jd.data == nil {
e2e.Failf("Data does not exist. It is empty: %v", jd.data)
}
listData, ok := jd.data.([]interface{})
if !ok {
e2e.Failf("Data is not a list: %v", jd.data)
}
ret := []*JSONData{}
for _, data := range listData {
ret = append(ret, &JSONData{data})
}
return ret
}
|
mco
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.