Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Do not merge!] Test Jira automation #852

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The operator deploys and manages resources needed by these four components:
- [Template Validator](https://github.com/kubevirt/ssp-operator/tree/master/internal/template-validator) (You can read more about it here: [Template Validator old repository](https://github.com/kubevirt/kubevirt-template-validator))
- [Common Templates Bundle](https://github.com/kubevirt/common-templates)
- [VM Console Proxy](https://github.com/kubevirt/vm-console-proxy)
- [KubeVirt Tekton Tasks](https://github.com/kubevirt/kubevirt-tekton-tasks)
- Metrics rules - Currently it is only a single Prometheus rule containing the count of all running VMs.

## Installation
Expand All @@ -28,13 +29,17 @@ The following resource types and CRDs are needed by `ssp-operator` when deployed
| `template.openshift.io/v1` | `common-templates` operand (Kind `Template`) |
| `virtualmachineclusterinstancetypes.instancetypes.kubevirt.io/v1alpha2` | `common-instancetypes` operand (Kind `VirtualMachineClusterInstancetype`) |
| `virtualmachineclusterpreferences.instancetypes.kubevirt.io/v1alpha2` | `common-instancetypes` operand (Kind `VirtualMachineClusterPreference`) |
| `pipelines.tekton.dev` | `tekton-pipelines` operand (Kind `Pipeline`) |
| `tasks.tekton.dev` | `tekton-tasks` operand (Kind `Task`) |

The following resource types and CRDs are needed by `ssp-operator` when deployed on a vanilla k8s environment:

| Resource type / CRD | Needed by |
| ------------------------------------------------------------------------| --------------------------------------------------------------------------|
| `virtualmachineclusterinstancetypes.instancetypes.kubevirt.io/v1alpha2` | `common-instancetypes` operand (Kind `VirtualMachineClusterInstancetype`) |
| `virtualmachineclusterpreferences.instancetypes.kubevirt.io/v1alpha2` | `common-instancetypes` operand (Kind `VirtualMachineClusterPreference`) |
| `pipelines.tekton.dev` | `tekton-pipelines` operand (Kind `Pipeline`) |
| `tasks.tekton.dev` | `tekton-tasks` operand (Kind `Task`) |

### Using HCO

Expand Down
24 changes: 24 additions & 0 deletions api/v1beta1/ssp_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,30 @@ type SSPSpec struct {

// CommonInstancetypes is the configuration of the common-instancetypes operand
CommonInstancetypes *CommonInstancetypes `json:"commonInstancetypes,omitempty"`

// TektonPipelines is the configuration of the tekton-pipelines operand
TektonPipelines *TektonPipelines `json:"tektonPipelines,omitempty"`

// TektonTasks is the configuration of the tekton-tasks operand
TektonTasks *TektonTasks `json:"tektonTasks,omitempty"`

// FeatureGates is the configuration of the tekton operands
FeatureGates *FeatureGates `json:"featureGates,omitempty"`
}

// TektonPipelines defines the desired state of pipelines
type TektonPipelines struct {
Namespace string `json:"namespace,omitempty"`
}

// TektonTasks defines variables for configuration of tasks
type TektonTasks struct {
Namespace string `json:"namespace,omitempty"`
}

// FeatureGates defines feature gate for tto operator
type FeatureGates struct {
DeployTektonTaskResources bool `json:"deployTektonTaskResources,omitempty"`
}

// DataImportCronTemplate defines the template type for DataImportCrons.
Expand Down
60 changes: 60 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

3 changes: 3 additions & 0 deletions automation/common/deploy-kubevirt-and-cdi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ metadata:
name: ${NAMESPACE}
EOF

# Deploy Tekton
oc apply -f "https://github.com/tektoncd/operator/releases/download/${TEKTON_VERSION}/openshift-release.yaml"

# Deploying kuebvirt
oc apply -n $NAMESPACE -f "https://github.com/kubevirt/kubevirt/releases/download/${KUBEVIRT_VERSION}/kubevirt-operator.yaml"

Expand Down
12 changes: 8 additions & 4 deletions automation/common/versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,22 @@ function latest_patch_version() {
}

function latest_version() {
local repo="$1"
local org="$1"
local repo="$2"

# The API call sorts releases by creation timestamp, so it is enough to request only a few latest ones.
curl --fail -s "https://api.github.com/repos/kubevirt/${repo}/releases" | \
curl --fail -s "https://api.github.com/repos/${org}/${repo}/releases" | \
jq '.[] | select(.prerelease==false) | .tag_name' | \
tr -d '"' | \
sort --version-sort | \
tail -n1
}

# Latest released Kubevirt version
KUBEVIRT_VERSION=$(latest_version "kubevirt")
KUBEVIRT_VERSION=$(latest_version "kubevirt" "kubevirt")

# Latest released CDI version
CDI_VERSION=$(latest_version "containerized-data-importer")
CDI_VERSION=$(latest_version "kubevirt" "containerized-data-importer")

# Latest released Tekton version
TEKTON_VERSION=$(latest_version "tektoncd" "operator")
118 changes: 118 additions & 0 deletions automation/e2e-tekton/example-pipelines-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#!/bin/bash

cp -L $KUBECONFIG /tmp/kubeconfig && export KUBECONFIG=/tmp/kubeconfig
export IMG=${CI_OPERATOR_IMG}

# switch to faster storage class for example pipelines tests (slower storage class is causing timeouts due
# to not able to copy whole windows disk)
if ! oc get storageclass | grep -q 'ssd-csi (default)' > /dev/null; then
oc annotate storageclass ssd-csi storageclass.kubernetes.io/is-default-class=true --overwrite
oc annotate storageclass standard-csi storageclass.kubernetes.io/is-default-class- --overwrite
fi

# Deploy resources
echo "Deploying resources"
./automation/common/deploy-kubevirt-and-cdi.sh

# remove tsc node labels which causes that windows VMs could not be scheduled due to different value in tsc node selector
for node in $(oc get nodes -o name -l node-role.kubernetes.io/worker); do
tscLabel="$(oc describe $node | grep scheduling.node.kubevirt.io/tsc-frequency- | xargs | cut -d"=" -f1)"
# disable node labeller
oc annotate ${node} node-labeller.kubevirt.io/skip-node=true --overwrite
# remove tsc labels
oc label ${node} cpu-timer.node.kubevirt.io/tsc-frequency- --overwrite
oc label ${node} cpu-timer.node.kubevirt.io/tsc-scalable- --overwrite
oc label ${node} ${tscLabel}- --overwrite
done

# SECRET
accessKeyId="/tmp/secrets/accessKeyId"
secretKey="/tmp/secrets/secretKey"

if test -f "$accessKeyId" && test -f "$secretKey"; then
id=$(cat $accessKeyId | tr -d '\n' | base64)
token=$(cat $secretKey | tr -d '\n' | base64 | tr -d ' \n')

oc apply -n kubevirt -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
name: tekton-operator-container-disk-puller
namespace: kubevirt
type: Opaque
data:
accessKeyId: "${id}"
secretKey: "${token}"
EOF
fi

function wait_until_exists() {
timeout 10m bash <<- EOF
until oc get $1; do
sleep 5
done
EOF
}

function wait_for_pipelinerun() {
oc wait -n kubevirt --for=condition=Succeeded=True pipelinerun -l pipelinerun=$1-run --timeout=60m &
success_pid=$!

oc wait -n kubevirt --for=condition=Succeeded=False pipelinerun -l pipelinerun=$1-run --timeout=60m && exit 1 &
failure_pid=$!

wait -n $success_pid $failure_pid

if (( $? == 0 )); then
echo "Pipelinerun $1 succeeded"
else
echo "Pipelinerun $1 failed"
exit 1
fi
}

# Disable smart cloning - it does not work properly on azure clusters, when this issue gets fixed we can enable it again - https://issues.redhat.com/browse/CNV-21844
oc patch cdi cdi --type merge -p '{"spec":{"cloneStrategyOverride":"copy"}}'

echo "Creating datavolume with windows iso"
oc apply -f "automation/e2e-tekton/test-files/${TARGET}-dv.yaml"

echo "Waiting for pvc to be created"
wait_until_exists "pvc -n kubevirt iso-dv -o jsonpath='{.metadata.annotations.cdi\.kubevirt\.io/storage\.pod\.phase}'"
oc wait -n kubevirt pvc iso-dv --timeout=10m --for=jsonpath='{.metadata.annotations.cdi\.kubevirt\.io/storage\.pod\.phase}'='Succeeded'

echo "Create config map for http server"
oc apply -f "automation/e2e-tekton/test-files/configmap.yaml"

echo "Deploying http-server to serve iso file to pipeline"
oc apply -f "automation/e2e-tekton/test-files/http-server.yaml"

wait_until_exists "pods -n kubevirt -l app=http-server"

echo "Waiting for http server to be ready"
oc wait -n kubevirt --for=condition=Ready pod -l app=http-server --timeout=10m

echo "Deploy SSP and create sample"
make deploy

# Deploy tekton task sample
oc apply -f "config/samples/ssp_v1beta1_ssp.yaml"
wait_until_exists "pipeline windows-efi-installer -n kubevirt" wait_until_exists "pipeline windows-customize -n kubevirt"

# Run windows10/11/2022-installer pipeline
echo "Running ${TARGET}-installer pipeline"
oc create -n kubevirt -f "automation/e2e-tekton/test-files/${TARGET}-installer-pipelinerun.yaml"
wait_until_exists "pipelinerun -n kubevirt -l pipelinerun=${TARGET}-installer-run"

# Wait for pipeline to finish
echo "Waiting for pipeline to finish"
wait_for_pipelinerun "${TARGET}-installer"

# Run windows-customize pipeline
echo "Running windows-customize pipeline"
oc create -n kubevirt -f "automation/e2e-tekton/test-files/${TARGET}-customize-pipelinerun.yaml"
wait_until_exists "pipelinerun -n kubevirt -l pipelinerun=${TARGET}-customize-run"

# Wait for pipeline to finish
echo "Waiting for pipeline to finish"
wait_for_pipelinerun "${TARGET}-customize"
20 changes: 20 additions & 0 deletions automation/e2e-tekton/test-files/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-conf
namespace: kubevirt
data:
nginx.conf: |
worker_processes 3;
pid /tmp/nginx.pid;
error_log /var/log/nginx/error.log;
events {
worker_connections 10240;
}
http {
server {
listen 8080;
server_name _;
location / {}
}
}
50 changes: 50 additions & 0 deletions automation/e2e-tekton/test-files/http-server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: http-server
namespace: kubevirt
labels:
app: http-server
spec:
selector:
matchLabels:
app: http-server
replicas: 1
template:
metadata:
labels:
app: http-server
spec:
volumes:
- name: nginx-config
configMap:
name: nginx-conf
- name: iso-dv
persistentVolumeClaim:
claimName: iso-dv
containers:
- name: http-server
image: nginxinc/nginx-unprivileged:latest
ports:
- containerPort: 8080
volumeMounts:
- mountPath: "/etc/nginx/html"
name: iso-dv
- mountPath: "/etc/nginx/nginx.conf"
subPath: nginx.conf
name: nginx-config
---
apiVersion: v1
kind: Service
metadata:
name: http-server
namespace: kubevirt
labels:
app: http-server
spec:
ports:
- port: 80
targetPort: 8080
protocol: TCP
selector:
app: http-server
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
generateName: windows10-customize-run-
labels:
pipelinerun: windows10-customize-run
spec:
params:
- name: allowReplaceGoldenTemplate
value: true
- name: allowReplaceCustomizationTemplate
value: true
pipelineRef:
name: windows-customize
taskRunSpecs:
- pipelineTaskName: copy-template-customize
taskServiceAccountName: copy-template-task
- pipelineTaskName: modify-vm-template-customize
taskServiceAccountName: modify-vm-template-task
- pipelineTaskName: create-vm-from-template
taskServiceAccountName: create-vm-from-template-task
- pipelineTaskName: wait-for-vmi-status
taskServiceAccountName: wait-for-vmi-status-task
- pipelineTaskName: create-base-dv
taskServiceAccountName: modify-data-object-task
- pipelineTaskName: cleanup-vm
taskServiceAccountName: cleanup-vm-task
- pipelineTaskName: copy-template-golden
taskServiceAccountName: copy-template-task
- pipelineTaskName: modify-vm-template-golden
taskServiceAccountName: modify-vm-template-task
status: {}
Loading