Skip to content

Commit

Permalink
[RFR] Add 'env' field to IQE CJI spec (#855)
Browse files Browse the repository at this point in the history
* Add 'env' field to IQE CJI spec
* Add logic for updating env vars and kuttl tests
* Update IQEJobSpec CRD documentation
* Fix implicit memory aliasing in for loop
  • Loading branch information
bsquizz authored Sep 12, 2023
1 parent 992e294 commit 7eef6ce
Show file tree
Hide file tree
Showing 9 changed files with 534 additions and 127 deletions.
44 changes: 23 additions & 21 deletions apis/cloud.redhat.com/v1alpha1/clowdjobinvocation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

batchv1 "k8s.io/api/batch/v1"

core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
Expand All @@ -46,54 +47,55 @@ type JobTestingSpec struct {
}

type IqeJobSpec struct {
// By default, Clowder will set the image on the ClowdJob to be the
// baseImage:name-of-iqe-plugin, but only the tag can be overridden here
// Image tag to use for IQE container. By default, Clowder will set the image tag to be
// baseImage:name-of-iqe-plugin, where baseImage is defined in the ClowdEnvironment. Only the tag can be overridden here.
ImageTag string `json:"imageTag,omitempty"`

// By default, Clowder will use the plugin name indicated in the ClowdApp's
// spec.testing.iqePlugin field. A comma,separated,list of plugins can be supplied
// here if you wish you override the plugins.
// A comma,separated,list indicating IQE plugin(s) to run tests for. By default, Clowder will use the plugin name given on the ClowdApp's
// spec.testing.iqePlugin field. Use this field if you wish you override the plugin list.
IqePlugins string `json:"plugins,omitempty"`

// Indiciates the presence of a selenium container
// Note: currently not implemented
// Defines configuration for a selenium container (optional)
UI IqeUISpec `json:"ui,omitempty"`

// sets the pytest -m args
// Specifies environment variables to set on the IQE container
Env *[]core.EnvVar `json:"env,omitempty"`

// Changes entrypoint to invoke 'iqe container-debug' so that container starts but does not run tests, allowing 'rsh' to be invoked
Debug bool `json:"debug,omitempty"`

// (DEPRECATED, using 'env' now preferred) sets IQE_MARKER_EXPRESSION env var on the IQE container
Marker string `json:"marker,omitempty"`

// sets value for ENV_FOR_DYNACONF
// (DEPRECATED, using 'env' now preferred) sets ENV_FOR_DYNACONF env var on the IQE container
DynaconfEnvName string `json:"dynaconfEnvName"`

// sets pytest -k args
// (DEPRECATED, using 'env' now preferred) sets IQE_FILTER_EXPRESSION env var on the IQE container
Filter string `json:"filter,omitempty"`

// Use to start the IQE pod without running tests and leave it up so that 'rsh' can be invoked
Debug bool `json:"debug,omitempty"`

// sets values passed to IQE '--requirements' arg
// (DEPRECATED, using 'env' now preferred) sets IQE_REQUIREMENTS env var on the IQE container
Requirements *[]string `json:"requirements,omitempty"`

// sets values passed to IQE '--requirements-priority' arg
// (DEPRECATED, using 'env' now preferred) sets IQE_REQUIREMENTS_PRIORITY env var on the IQE container
RequirementsPriority *[]string `json:"requirementsPriority,omitempty"`

// sets values passed to IQE '--test-importance' arg
// (DEPRECATED, using 'env' now preferred) sets IQE_TEST_IMPORTANCE env var on the IQE container
TestImportance *[]string `json:"testImportance,omitempty"`

// sets value for IQE_LOG_LEVEL (default if empty: "info")
// (DEPRECATED, using 'env' now preferred) sets IQE_LOG_LEVEL env var on the IQE container
//+kubebuilder:validation:Enum={"", "critical", "error", "warning", "info", "debug", "notset"}
LogLevel string `json:"logLevel,omitempty"`

// sets value passed to IQE 'IQE_PARALLEL_ENABLED' arg
// (DEPRECATED, using 'env' now preferred) sets IQE_PARALLEL_ENABLED env var on the IQE container
ParallelEnabled string `json:"parallelEnabled,omitempty"`

// sets value passed to IQE 'IQE_PARALLEL_WORKER_COUNT' arg
// (DEPRECATED, using 'env' now preferred) sets IQE_PARALLEL_WORKER_COUNT env var on the IQE container
ParallelWorkerCount string `json:"parallelWorkerCount,omitempty"`

// sets value passed to IQE 'IQE_RP_ARGS' report portal args
// (DEPRECATED, using 'env' now preferred) sets IQE_RP_ARGS env var on the IQE container
RpArgs string `json:"rpArgs,omitempty"`

// sets value passed to IQE 'IQE_IBUTSU_SOURCE' args
// (DEPRECATED, using 'env' now preferred) sets IQE_IBUTSU_SOURCE env var on the IQE container
IbutsuSource string `json:"ibutsuSource,omitempty"`
}

Expand Down
11 changes: 11 additions & 0 deletions apis/cloud.redhat.com/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

179 changes: 150 additions & 29 deletions config/crd/bases/cloud.redhat.com_clowdjobinvocations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,146 @@ spec:
ClowdApp's definition of the job
properties:
debug:
description: Use to start the IQE pod without running tests
and leave it up so that 'rsh' can be invoked
description: Changes entrypoint to invoke 'iqe container-debug'
so that container starts but does not run tests, allowing
'rsh' to be invoked
type: boolean
dynaconfEnvName:
description: sets value for ENV_FOR_DYNACONF
description: (DEPRECATED, using 'env' now preferred) sets
ENV_FOR_DYNACONF env var on the IQE container
type: string
env:
description: Specifies environment variables to set on the
IQE container
items:
description: EnvVar represents an environment variable present
in a Container.
properties:
name:
description: Name of the environment variable. Must
be a C_IDENTIFIER.
type: string
value:
description: 'Variable references $(VAR_NAME) are expanded
using the previously defined environment variables
in the container and any service environment variables.
If a variable cannot be resolved, the reference in
the input string will be unchanged. Double $$ are
reduced to a single $, which allows for escaping the
$(VAR_NAME) syntax: i.e. "$$(VAR_NAME)" will produce
the string literal "$(VAR_NAME)". Escaped references
will never be expanded, regardless of whether the
variable exists or not. Defaults to "".'
type: string
valueFrom:
description: Source for the environment variable's value.
Cannot be used if value is not empty.
properties:
configMapKeyRef:
description: Selects a key of a ConfigMap.
properties:
key:
description: The key to select.
type: string
name:
description: 'Name of the referent. More info:
https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion,
kind, uid?'
type: string
optional:
description: Specify whether the ConfigMap or
its key must be defined
type: boolean
required:
- key
type: object
fieldRef:
description: 'Selects a field of the pod: supports
metadata.name, metadata.namespace, `metadata.labels[''<KEY>'']`,
`metadata.annotations[''<KEY>'']`, spec.nodeName,
spec.serviceAccountName, status.hostIP, status.podIP,
status.podIPs.'
properties:
apiVersion:
description: Version of the schema the FieldPath
is written in terms of, defaults to "v1".
type: string
fieldPath:
description: Path of the field to select in
the specified API version.
type: string
required:
- fieldPath
type: object
resourceFieldRef:
description: 'Selects a resource of the container:
only resources limits and requests (limits.cpu,
limits.memory, limits.ephemeral-storage, requests.cpu,
requests.memory and requests.ephemeral-storage)
are currently supported.'
properties:
containerName:
description: 'Container name: required for volumes,
optional for env vars'
type: string
divisor:
anyOf:
- type: integer
- type: string
description: Specifies the output format of
the exposed resources, defaults to "1"
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
resource:
description: 'Required: resource to select'
type: string
required:
- resource
type: object
secretKeyRef:
description: Selects a key of a secret in the pod's
namespace
properties:
key:
description: The key of the secret to select
from. Must be a valid secret key.
type: string
name:
description: 'Name of the referent. More info:
https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion,
kind, uid?'
type: string
optional:
description: Specify whether the Secret or its
key must be defined
type: boolean
required:
- key
type: object
type: object
required:
- name
type: object
type: array
filter:
description: sets pytest -k args
description: (DEPRECATED, using 'env' now preferred) sets
IQE_FILTER_EXPRESSION env var on the IQE container
type: string
ibutsuSource:
description: sets value passed to IQE 'IQE_IBUTSU_SOURCE'
args
description: (DEPRECATED, using 'env' now preferred) sets
IQE_IBUTSU_SOURCE env var on the IQE container
type: string
imageTag:
description: By default, Clowder will set the image on the
ClowdJob to be the baseImage:name-of-iqe-plugin, but only
the tag can be overridden here
description: Image tag to use for IQE container. By default,
Clowder will set the image tag to be baseImage:name-of-iqe-plugin,
where baseImage is defined in the ClowdEnvironment. Only
the tag can be overridden here.
type: string
logLevel:
description: 'sets value for IQE_LOG_LEVEL (default if empty:
"info")'
description: (DEPRECATED, using 'env' now preferred) sets
IQE_LOG_LEVEL env var on the IQE container
enum:
- ""
- critical
Expand All @@ -93,46 +212,48 @@ spec:
- notset
type: string
marker:
description: sets the pytest -m args
description: (DEPRECATED, using 'env' now preferred) sets
IQE_MARKER_EXPRESSION env var on the IQE container
type: string
parallelEnabled:
description: sets value passed to IQE 'IQE_PARALLEL_ENABLED'
arg
description: (DEPRECATED, using 'env' now preferred) sets
IQE_PARALLEL_ENABLED env var on the IQE container
type: string
parallelWorkerCount:
description: sets value passed to IQE 'IQE_PARALLEL_WORKER_COUNT'
arg
description: (DEPRECATED, using 'env' now preferred) sets
IQE_PARALLEL_WORKER_COUNT env var on the IQE container
type: string
plugins:
description: By default, Clowder will use the plugin name
indicated in the ClowdApp's spec.testing.iqePlugin field.
A comma,separated,list of plugins can be supplied here if
you wish you override the plugins.
description: A comma,separated,list indicating IQE plugin(s)
to run tests for. By default, Clowder will use the plugin
name given on the ClowdApp's spec.testing.iqePlugin field.
Use this field if you wish you override the plugin list.
type: string
requirements:
description: sets values passed to IQE '--requirements' arg
description: (DEPRECATED, using 'env' now preferred) sets
IQE_REQUIREMENTS env var on the IQE container
items:
type: string
type: array
requirementsPriority:
description: sets values passed to IQE '--requirements-priority'
arg
description: (DEPRECATED, using 'env' now preferred) sets
IQE_REQUIREMENTS_PRIORITY env var on the IQE container
items:
type: string
type: array
rpArgs:
description: sets value passed to IQE 'IQE_RP_ARGS' report
portal args
description: (DEPRECATED, using 'env' now preferred) sets
IQE_RP_ARGS env var on the IQE container
type: string
testImportance:
description: sets values passed to IQE '--test-importance'
arg
description: (DEPRECATED, using 'env' now preferred) sets
IQE_TEST_IMPORTANCE env var on the IQE container
items:
type: string
type: array
ui:
description: 'Indiciates the presence of a selenium container
Note: currently not implemented'
description: Defines configuration for a selenium container
(optional)
properties:
enabled:
description: No longer used
Expand Down
22 changes: 22 additions & 0 deletions controllers/cloud.redhat.com/providers/iqe/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ func joinNullableSlice(s *[]string) string {
return ""
}

func updateEnvVars(existingEnvVars []core.EnvVar, newEnvVars []core.EnvVar) []core.EnvVar {
for _, newEnvVar := range newEnvVars {
replaced := false
for idx, existingEnvVar := range existingEnvVars {
if existingEnvVar.Name == newEnvVar.Name {
p := &existingEnvVars[idx]
p.Value = newEnvVar.Value
replaced = true
}
}
if !replaced {
existingEnvVars = append(existingEnvVars, newEnvVar)
}
}

return existingEnvVars
}

func createIqeContainer(j *batchv1.Job, nn types.NamespacedName, cji *crd.ClowdJobInvocation, env *crd.ClowdEnvironment, app *crd.ClowdApp) *core.Container {
// create env vars
iqePlugins := app.Spec.Testing.IqePlugin
Expand Down Expand Up @@ -67,6 +85,10 @@ func createIqeContainer(j *batchv1.Job, nn types.NamespacedName, cji *crd.ClowdJ
{Name: "IQE_IBUTSU_SOURCE", Value: cji.Spec.Testing.Iqe.IbutsuSource},
}

if cji.Spec.Testing.Iqe.Env != nil {
envVars = updateEnvVars(envVars, *cji.Spec.Testing.Iqe.Env)
}

// set image tag
iqeImage := env.Spec.Providers.Testing.Iqe.ImageBase

Expand Down
Loading

0 comments on commit 7eef6ce

Please sign in to comment.