Documentation ¶
Index ¶
- Constants
- Variables
- func ApplyPlacement(ctx SpecContext, namespace, policyName string) error
- func CleanupHubNamespace(namespace string)
- func CleanupOCPUser(client kubernetes.Interface, dynamicClient dynamic.Interface, user OCPUser) error
- func CreateOCPUser(client kubernetes.Interface, dynamicClient dynamic.Interface, user OCPUser) error
- func DeletePlacement(namespace, policyName string) error
- func DoCleanupPolicy(policyFile string, templateGVRs ...schema.GroupVersionResource)
- func DoCreatePolicyTest(policyFile string, templateGVRs ...schema.GroupVersionResource)
- func DoHistoryUpdatedTest(policyName string, messages ...string)
- func DoRootComplianceTest(policyName string, compliance policiesv1.ComplianceState)
- func EnforcePolicy(policyName string, templateGVRs ...schema.GroupVersionResource)
- func GenerateInsecurePassword() (string, error)
- func GetClusterComplianceState(policyName, clusterName string) func(Gomega) interface{}
- func GetComplianceState(policyName string) func(Gomega) interface{}
- func GetDuplicateHistoryMessage(policyName string) string
- func GetHistoryMessages(policyName string, templateIdx int) ([]interface{}, bool, error)
- func GetKubeConfig(server, username, password string) (string, error)
- func GetLatestStatusMessage(policyName string, templateIdx int) func() string
- func GetOpPolicyCompMsg(policyName string) func() string
- func GetWithToken(url, authToken string) (body, status string, err error)
- func GitOpsCleanup(ctx SpecContext, user OCPUser)
- func GitOpsUserSetup(ctx SpecContext, ocpUser *OCPUser)
- func InformPolicy(policyName string, templateGVRs ...schema.GroupVersionResource)
- func InitFlags(flagset *flag.FlagSet)
- func InitInterfaces(hubConfig, managedConfig string, isHosted bool)
- func IsAtLeastVersion(minVersion string) bool
- func LoadConfig(url, kubeconfig, context string) (*rest.Config, error)
- func MatchMetricValue(name, label, value string) types.GomegaMatcher
- func NewKubeClient(url, kubeconfig, context string) kubernetes.Interface
- func NewKubeClientDynamic(url, kubeconfig, context string) dynamic.Interface
- func OcHosting(args ...string) (string, error)
- func OcHub(args ...string) (string, error)
- func OcManaged(args ...string) (string, error)
- func OcUser(user OCPUser, args ...string) (string, error)
- func OutputDebugInfo(testName string, kubeconfig string, additionalResources ...string)
- func PatchPlacementRule(namespace, name string) error
- func RegisterDebugMessage() *string
- type OCPUser
Constants ¶
const MaxTimeoutSeconds = 900 // 15 minutes
Variables ¶
var ( KubeconfigHub string KubeconfigManaged string UserNamespace string ClusterNamespace string ClusterNamespaceOnHub string PolicyCollectionBranch string OCMNamespace string OCMAddOnNamespace string DefaultTimeoutSeconds int ManuallyPatchDecisions bool K8sClient string IsHosted bool ClientHub kubernetes.Interface ClientHubDynamic dynamic.Interface ClientManaged kubernetes.Interface ClientManagedDynamic dynamic.Interface ClientHosting kubernetes.Interface ClientHostingDynamic dynamic.Interface )
var ( GvrPod = schema.GroupVersionResource{ Version: "v1", Resource: "pods", } GvrNS = schema.GroupVersionResource{ Version: "v1", Resource: "namespaces", } GvrConfigMap = schema.GroupVersionResource{ Version: "v1", Resource: "configmaps", } GvrRole = schema.GroupVersionResource{ Group: "rbac.authorization.k8s.io", Version: "v1", Resource: "roles", } GvrCRD = schema.GroupVersionResource{ Group: "apiextensions.k8s.io", Version: "v1", Resource: "customresourcedefinitions", } GvrPolicy = schema.GroupVersionResource{ Group: "policy.open-cluster-management.io", Version: "v1", Resource: "policies", } GvrPolicySet = schema.GroupVersionResource{ Group: "policy.open-cluster-management.io", Version: "v1beta1", Resource: "policysets", } GvrConfigurationPolicy = schema.GroupVersionResource{ Group: "policy.open-cluster-management.io", Version: "v1", Resource: "configurationpolicies", } GvrOperatorPolicy = schema.GroupVersionResource{ Group: "policy.open-cluster-management.io", Version: "v1beta1", Resource: "operatorpolicies", } GvrSubscriptionOLM = schema.GroupVersionResource{ Group: "operators.coreos.com", Version: "v1alpha1", Resource: "subscriptions", } GvrOperatorGroup = schema.GroupVersionResource{ Group: "operators.coreos.com", Version: "v1", Resource: "operatorgroups", } GvrClusterServiceVersion = schema.GroupVersionResource{ Group: "operators.coreos.com", Version: "v1alpha1", Resource: "clusterserviceversions", } GvrCertPolicy = schema.GroupVersionResource{ Group: "policy.open-cluster-management.io", Version: "v1", Resource: "certificatepolicies", } GvrDeployment = schema.GroupVersionResource{ Group: "apps", Version: "v1", Resource: "deployments", } GvrPlacementBinding = schema.GroupVersionResource{ Group: "policy.open-cluster-management.io", Version: "v1", Resource: "placementbindings", } GvrPlacementRule = schema.GroupVersionResource{ Group: "apps.open-cluster-management.io", Version: "v1", Resource: "placementrules", } GvrSubscription = schema.GroupVersionResource{ Group: "apps.open-cluster-management.io", Version: "v1", Resource: "subscriptions", } GvrK8sRequiredLabels = schema.GroupVersionResource{ Group: "constraints.gatekeeper.sh", Version: "v1beta1", Resource: "k8srequiredlabels", } GvrClusterVersion = schema.GroupVersionResource{ Group: "config.openshift.io", Version: "v1", Resource: "clusterversions", } GvrAPIServer = schema.GroupVersionResource{ Group: "config.openshift.io", Version: "v1", Resource: "apiservers", } GvrComplianceScan = schema.GroupVersionResource{ Group: "compliance.openshift.io", Version: "v1alpha1", Resource: "compliancescans", } GvrComplianceSuite = schema.GroupVersionResource{ Group: "compliance.openshift.io", Version: "v1alpha1", Resource: "compliancesuites", } GvrComplianceCheckResult = schema.GroupVersionResource{ Group: "compliance.openshift.io", Version: "v1alpha1", Resource: "compliancecheckresults", } GvrSCC = schema.GroupVersionResource{ Group: "security.openshift.io", Version: "v1", Resource: "securitycontextconstraints", } GvrRoute = schema.GroupVersionResource{ Group: "route.openshift.io", Version: "v1", Resource: "routes", } GvrOAuth = schema.GroupVersionResource{ Group: "config.openshift.io", Version: "v1", Resource: "oauths", } GvrUser = schema.GroupVersionResource{ Group: "user.openshift.io", Version: "v1", Resource: "users", } GvrIdentity = schema.GroupVersionResource{ Group: "user.openshift.io", Version: "v1", Resource: "identities", } GvrManagedClusterSet = schema.GroupVersionResource{ Group: "cluster.open-cluster-management.io", Version: "v1beta2", Resource: "managedclustersets", } GvrAddonDeploymentConfig = schema.GroupVersionResource{ Group: "addon.open-cluster-management.io", Version: "v1alpha1", Resource: "addondeploymentconfigs", } GvrClusterManagementAddOn = schema.GroupVersionResource{ Group: "addon.open-cluster-management.io", Version: "v1alpha1", Resource: "clustermanagementaddons", } GvrManagedClusterSetBinding = schema.GroupVersionResource{ Group: "cluster.open-cluster-management.io", Version: "v1beta2", Resource: "managedclustersetbindings", } GvrPlacement = schema.GroupVersionResource{ Group: "cluster.open-cluster-management.io", Version: "v1beta1", Resource: "placements", } )
Functions ¶
func ApplyPlacement ¶
ApplyPlacement function creates Placement and PlacementBinding so that it will always only match the targetCluster.
func CleanupHubNamespace ¶
func CleanupHubNamespace(namespace string)
func CleanupOCPUser ¶
func CleanupOCPUser( client kubernetes.Interface, dynamicClient dynamic.Interface, user OCPUser, ) error
CleanupOCPUser will revert changes made to the cluster by the CreateOCPUser function.
func CreateOCPUser ¶
func CreateOCPUser( client kubernetes.Interface, dynamicClient dynamic.Interface, user OCPUser, ) error
CreateOCPUser will create an OpenShift user on a cluster, configure the identity provider for that user, and add the desired roles to the user. This function is idempotent.
func DeletePlacement ¶
DeletePlacement delete applied Placement and PlacementBinding
func DoCleanupPolicy ¶
func DoCleanupPolicy(policyFile string, templateGVRs ...schema.GroupVersionResource)
DoCleanupPolicy deletes the resources specified in the file, and asserts that the propagated policy was removed from the managed cluster. For each templateGVR, it will check that there is no longer a policy template (for example ConfigurationPolicy) of the same name on the managed cluster.
func DoCreatePolicyTest ¶
func DoCreatePolicyTest(policyFile string, templateGVRs ...schema.GroupVersionResource)
DoCreatePolicyTest runs usual assertions around creating a policy. It will create the given policy file to the hub cluster, on the user namespace. It also patches the PlacementRule with a PlacementDecision if required. It asserts that the policy was distributed to the managed cluster, and for any templateGVRs supplied, it asserts that a policy template of that type (for example ConfigurationPolicy) and the same name was created on the managed cluster.
It assumes that the given filename (stripped of an extension) matches the name of the policy, and that the PlacementRule has the same name, with '-plr' appended.
func DoHistoryUpdatedTest ¶
func DoRootComplianceTest ¶
func DoRootComplianceTest(policyName string, compliance policiesv1.ComplianceState)
DoRootComplianceTest asserts that the given policy has the given compliance on the root policy on the hub cluster.
func EnforcePolicy ¶
func EnforcePolicy(policyName string, templateGVRs ...schema.GroupVersionResource)
EnforcePolicy patches the root policy to be enforced and verifies that it propagates. Note: when checking a policy template, it assumes the template's name matches the root policy's name.
func GenerateInsecurePassword ¶
GenerateInsecurePassword is a random password generator from 15-30 bytes. It is insecure since the characters are limited to just hex values (i.e. 1-9,a-f) from the random bytes. An error is returned if the random bytes cannot be read.
func GetClusterComplianceState ¶
func GetClusterComplianceState(policyName, clusterName string) func(Gomega) interface{}
GetClusterComplianceState returns a function usable by ginkgo.Eventually that retrieves the compliance state of the input policy on the specified cluster.
func GetComplianceState ¶
func GetComplianceState(policyName string) func(Gomega) interface{}
GetComplianceState returns a function usable by ginkgo.Eventually that retrieves the compliance state of the input policy in the globally configured managed cluster.
func GetHistoryMessages ¶
func GetKubeConfig ¶
GetKubeConfig will generate a kubeconfig file based on an OpenShift user. The path of the kubeconfig file is returned. It is the responsibility of the caller to delete the kubeconfig file after use.
func GetLatestStatusMessage ¶
GetLatestStatusMessage returns the most recent status message for the given policy template. If the policy, template, or status do not exist for any reason, an empty string is returned.
func GetOpPolicyCompMsg ¶
GetOpPolicyCompMsg returns a function (so that it can be used in an Eventually) that returns the current Compliant condition message on the specified OperatorPolicy. It will return an empty string if the OperatorPolicy or condition could not be found.
func GetWithToken ¶
GetWithToken makes a GET request to the given target, and puts the token in an Authorization header if non-empty. The HTTP client has a sane timeout, and will skip verifying the target certificate.
func GitOpsCleanup ¶
func GitOpsCleanup(ctx SpecContext, user OCPUser)
GitOpsCleanup will remove any test data/configuration on the OpenShift cluster that was added/updated as part of the GitOps test. The kubeconfig file is also deleted from the filesystem. Any errors will be propagated as gomega failed assertions.
func GitOpsUserSetup ¶
func GitOpsUserSetup(ctx SpecContext, ocpUser *OCPUser)
GitOpsUserSetup configures a new user to use for the GitOps tests. It updates the provided OCPUser instance, which contains a path to the created kubeconfig file.
func InformPolicy ¶
func InformPolicy(policyName string, templateGVRs ...schema.GroupVersionResource)
InformPolicy patches the root policy to be informed and verifies that it propagates. Note: when checking a policy template, it assumes the template's name matches the root policy's name.
func InitInterfaces ¶
Initializes the Hub and Managed Clients. Should be called after InitFlags, and before any tests using common functions are run.
func IsAtLeastVersion ¶
IsAtLeastVersion detects OCP versions given an x.y version lower bound
func MatchMetricValue ¶
func MatchMetricValue(name, label, value string) types.GomegaMatcher
MatchMetricValue returns a GomegaMatcher to look through the full response from a metrics endpoint and check for a specific data point.
func NewKubeClient ¶
func NewKubeClient(url, kubeconfig, context string) kubernetes.Interface
func NewKubeClientDynamic ¶
func OcHub ¶
Runs the given oc/kubectl command against the configured hub cluster. Prints and returns the stdout from the command. If the command fails (non-zero exit code) and stderr was populated, that content will be returned in the error.
func OcManaged ¶
Runs the given oc/kubectl command against the configured managed cluster. Prints and returns the stdout from the command. If the command fails (non-zero exit code) and stderr was populated, that content will be returned in the error.
func OcUser ¶
Runs the given oc/kubectl command using the given OCPUser. Prints and returns the stdout from the command. If the command fails (non-zero exit code) and stderr was populated, that content will be returned in the error.
func OutputDebugInfo ¶
func PatchPlacementRule ¶
Patches the clusterSelector of the specified PlacementRule so that it will always only match the targetCluster.
func RegisterDebugMessage ¶
func RegisterDebugMessage() *string
RegisterDebugMessage returns a pointer to a string which this function will register to be printed in the ginkgo logs only if the test fails.
Types ¶
type OCPUser ¶
type OCPUser struct { // If a namespace is not provided, a cluster role binding is created instead of a role binding. ClusterRoles []types.NamespacedName ClusterRoleBindings []string Password string Username string Kubeconfig string }
OCPUser represents an OpenShift user to be created on a cluster.