Skip to content

Commit

Permalink
Merge pull request #39 from RedHatGov/fix_gha
Browse files Browse the repository at this point in the history
Fix GHA
  • Loading branch information
jharmison-redhat authored Apr 9, 2021
2 parents b333fb4 + 42363df commit 9a500e1
Show file tree
Hide file tree
Showing 22 changed files with 86 additions and 51 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
- name: Kind
uses: engineerd/[email protected]
with:
config: molecule/kind-cluster/files/kind-config.yml
name: osdk-test
version: v0.9.0
config: molecule/kind/files/kind-config.yml
name: osdk-test-cluster
version: v0.10.0
- name: Prereq setup
run: hack/ci-setup.sh
- name: Test
Expand All @@ -40,9 +40,9 @@ jobs:
- name: Kind
uses: engineerd/[email protected]
with:
config: molecule/kind-cluster/files/kind-config.yml
name: osdk-test
version: v0.9.0
config: molecule/kind/files/kind-config.yml
name: osdk-test-namespace
version: v0.10.0
- name: Prereq setup
run: hack/ci-setup.sh
- name: Test
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
FROM quay.io/operator-framework/ansible-operator:v1.4.2

COPY requirements.yml ${HOME}/requirements.yml
RUN ansible-galaxy collection install -r ${HOME}/requirements.yml \
COPY requirements ${HOME}
RUN pip3 install --user --upgrade -r ${HOME}/requirements.txt \
&& ansible-galaxy collection install -r ${HOME}/requirements.yml \
&& chmod -R ug+rwx ${HOME}/.ansible

COPY watches.yaml ${HOME}/watches.yaml
Expand Down
26 changes: 11 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ uninstall: kustomize
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build --load_restrictor none config/${OVERLAY} | kubectl apply -f -
$(KUSTOMIZE) build --load-restrictor LoadRestrictionsNone config/${OVERLAY} | kubectl apply -f -

# Undeploy controller in the configured Kubernetes cluster in ~/.kube/config
undeploy: kustomize
$(KUSTOMIZE) build --load_restrictor none config/${OVERLAY} | kubectl delete -f -
$(KUSTOMIZE) build --load-restrictor LoadRestrictionsNone config/${OVERLAY} | kubectl delete -f -

# Build the docker image
docker-build:
Expand All @@ -69,22 +69,18 @@ SHELL := env PATH=$(PATH) /bin/sh
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH := $(shell uname -m | sed 's/x86_64/amd64/')

# Download kustomize locally if necessary, preferring the $(pwd)/bin path over global if both exist.
.PHONY: kustomize
# Download kustomize locally
KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize:
ifeq (,$(wildcard $(KUSTOMIZE)))
ifeq (,$(shell which kustomize 2>/dev/null))
bin/kustomize:
@{ \
set -e ;\
mkdir -p $(dir $(KUSTOMIZE)) ;\
curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v3.5.4/kustomize_v3.5.4_$(OS)_$(ARCH).tar.gz | \
tar xzf - -C bin/ ;\
set -e ;\
mkdir -p $(dir $(KUSTOMIZE)) ;\
curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v4.0.5/kustomize_v4.0.5_$(OS)_$(ARCH).tar.gz | \
tar xzf - -C $(dir $(KUSTOMIZE)) ;\
}
else
KUSTOMIZE = $(shell which kustomize)
endif
endif

.PHONY: kustomize
kustomize: bin/kustomize

# Download ansible-operator locally if necessary, preferring the $(pwd)/bin path over global if both exist.
.PHONY: ansible-operator
Expand Down
26 changes: 18 additions & 8 deletions hack/ci-setup.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
#!/bin/bash -ex
# Installs dependencies needed to run the tests in CI environment

function ll {
ls -halF "${@}"
}

mkdir -p $HOME/.local/bin
export PATH="$HOME/.local/bin:$PATH"
export KUBECONFIG=$HOME/.kube/config
export KUBECONFIG=${KUBECONFIG:-$HOME/.kube/config}
echo $KUBECONFIG
ll $HOME/.kube
kubectl config current-context
kind version
clusters=$(kind get clusters)
for cluster in $clusters; do
kind get nodes --name $cluster
kind get kubeconfig --name $cluster
done

# Basic pip prereqs
pip3 install --user --upgrade setuptools wheel pip

# Dependencies for test environment
pip3 install --user docker==4.2.2 ansible molecule ansible-lint yamllint flake8 openshift jmespath
pip3 install --user -r requirements/test-requirements.txt

# Ansible dependencies
ansible-galaxy collection install -r requirements.yml

# Kind CLI (for loading images into cluster)
curl -Lo $HOME/.local/bin/kind https://kind.sigs.k8s.io/dl/v0.9.0/kind-linux-amd64
chmod +x $HOME/.local/bin/kind
pip3 install --user --upgrade -r requirements/requirements.txt
ansible-galaxy collection install -r requirements/requirements.yml

# Helm CLI (for loading Ingress)
curl -Lo $HOME/helm.tgz https://get.helm.sh/helm-v3.5.2-linux-amd64.tar.gz
tar xvzf $HOME/helm.tgz -C $HOME/.local/bin --strip-components 1 linux-amd64/helm
helm repo add stable https://charts.helm.sh/stable
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
2 changes: 2 additions & 0 deletions hack/ci-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ export PATH="$HOME/.local/bin:$PATH"
export OPERATORDIR="$(pwd)"
make kustomize
[ -f ./bin/kustomize ] && export KUSTOMIZE_PATH="$(realpath ./bin/kustomize)" || export KUSTOMIZE_PATH="$(which kustomize)"
kustomize version ||:
./bin/kustomize version

TEST_OPERATOR_NAMESPACE=default molecule test -s $1
1 change: 1 addition & 0 deletions hack/operate.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ KIND=Gitea
CR_SAMPLE=redhatgov_v1alpha1_gitea_openshift.yaml
VERSION=0.0.6
CHANNELS=alpha
OSDK_VERSION=1.4.2
5 changes: 3 additions & 2 deletions hack/operate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ VERSION=
CHANNELS=
DEVLEOP=
BUNDLE=
OSDK_VERSION=latest
EXTRA_TAGS=()

# Load the configuration
Expand Down Expand Up @@ -312,7 +313,7 @@ function update_components() {
else
error_run "Updating the Operator SDK manager" 'pip3 install --user --upgrade -r "$SCRIPT_ROOT/requirements.txt"' || return 1
fi
error_run "Updating the Operator SDK" 'sdk_version=$(osdk-manager osdk update --no-verify -vvvv | cut -d" " -f 3)' || return 1
error_run "Updating the Operator SDK" 'sdk_version=$(osdk-manager osdk update --version $OSDK_VERSION -vvvv | cut -d" " -f 3)' || return 1
fi
components_updated=true
}
Expand Down Expand Up @@ -435,7 +436,7 @@ function publish_bundle() {
error_run "Adding namespaced Role to kustomization" 'kustomize edit add resource namespaced/role.yaml' || return 1
error_run "Adding namespaced RoleBinding to kustomization" 'kustomize edit add resource namespaced/role_binding.yaml' || return 1
popd &>/dev/null
error_run "Building bundle manifests" 'kustomize build --load_restrictor none config/manifests | operator-sdk generate bundle --overwrite --version $VERSION --channels "$CHANNELS"' || return 1
error_run "Building bundle manifests" 'kustomize build --load-restrictor LoadRestrictionsNone config/manifests | operator-sdk generate bundle --overwrite --version $VERSION --channels "$CHANNELS"' || return 1
error_run "Validating bundle" operator-sdk bundle validate ./bundle || return 1
error_run "Building bundle image" docker build -f bundle.Dockerfile -t "$IMG-bundle:$VERSION" . || return 1
if [ -z "$DEVELOP" ]; then
Expand Down
4 changes: 2 additions & 2 deletions molecule/default/kustomize.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Build kustomize testing overlay
# load_restrictor must be set to none so we can load patch files from the default overlay
command: '{{ kustomize }} build --load_restrictor none .'
# load-restrictor must be set to none so we can load patch files from the default overlay
command: '{{ kustomize }} build --load-restrictor LoadRestrictionsNone .'
args:
chdir: '{{ config_dir }}/testing/{{ scope|default("cluster") }}_scope'
register: resources
Expand Down
5 changes: 4 additions & 1 deletion molecule/default/tasks/gitea_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@

- name: Verify that Gitea failed to be created from the CR when appropriate
assert:
that: namespace_modded_cr.resources[0].status is not defined == (scope == "namespace")
that: namespace_modded_success == namespace_modded_expected
vars:
namespace_modded_success: '{{ namespace_modded_cr.resources[0].status is defined }}'
namespace_modded_expected: '{{ scope == "cluster" }}'

# TODO:
# - Validate Gitea can be used
15 changes: 10 additions & 5 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,24 @@
- api_version: v1
kind: ConfigMap
register: debug_resources
ignore_errors: true

- name: Retrieve controller Pod logs
k8s_log:
name: '{{ item.metadata.name }}'
namespace: '{{ namespace }}'
label_selectors:
- '{{ ctrl_label }}'
container: manager
loop: "{{ q('k8s', api_version='v1', kind='Pod', namespace=namespace, label_selector=ctrl_label) }}"
register: debug_controller_logs
ignore_errors: true

- name: Retrieve application Pod logs
k8s_log:
name: '{{ item.metadata.name }}'
namespace: '{{ namespace }}'
loop: "{{ q('k8s', api_version='v1', kind='Pod', namespace=namespace, label_selector='app=gitea-testing') }}"
label_selectors:
- app=gitea-testing
register: debug_app_logs
ignore_errors: true

- name: Output gathered resources
debug:
Expand All @@ -54,7 +57,9 @@
- name: Output gathered logs
debug:
var: item.log_lines
loop: '{{ debug_controller_logs.results + debug_app_logs.results }}'
loop:
- debug_controller_logs
- debug_app_logs

- name: Re-emit failure
vars:
Expand Down
3 changes: 3 additions & 0 deletions molecule/kind-cluster/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ platforms:
provisioner:
name: ansible
playbooks:
create: ../kind/create.yml
prepare: ../default/prepare.yml
converge: ../kind/converge.yml
verify: ../default/verify.yml
destroy: ../kind/destroy.yml
lint: |
set -e
ansible-lint
Expand Down
6 changes: 3 additions & 3 deletions molecule/kind-namespace/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ platforms:
provisioner:
name: ansible
playbooks:
create: ../kind-cluster/create.yml
create: ../kind/create.yml
prepare: ../default/prepare.yml
converge: ../kind-cluster/converge.yml
converge: ../kind/converge.yml
verify: ../default/verify.yml
destroy: ../kind-cluster/destroy.yml
destroy: ../kind/destroy.yml
lint: |
set -e
ansible-lint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
force_source: yes

- name: Load image into kind cluster
command: kind load docker-image --name osdk-test '{{ operator_image }}'
command: kind load docker-image --name osdk-test-{{ scope }} '{{ operator_image }}'
register: result
changed_when: '"not yet present" in result.stdout'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
tasks:
- name: Install nginx Ingress onto kind
command: >
helm install kind-ingress stable/nginx-ingress
helm install kind-ingress ingress-nginx/ingress-nginx
--set controller.service.type=NodePort
--set controller.service.nodePorts.http=30080
File renamed without changes.
File renamed without changes.
5 changes: 0 additions & 5 deletions requirements.yml

This file was deleted.

1 change: 1 addition & 0 deletions requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
openshift==0.11.2
6 changes: 6 additions & 0 deletions requirements/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
collections:
- name: community.kubernetes
version: 1.2.0
- name: operator_sdk.util
version: 0.1.0
8 changes: 8 additions & 0 deletions requirements/test-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
docker==4.2.2
ansible==2.9.15 # aligns with operator-sdk version
requests>=2.25,<2.26
molecule>=3.3,<3.4
ansible-lint>=5.0,<6.0
yamllint>=1.26,<2.0
flake8>=3.9,<4.0
jmespath>=0.10,<0.11
1 change: 1 addition & 0 deletions roles/gitea-ocp/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ _gitea_expose_method: Route
_gitea_expose_uri: ""
_gitea_route: "{{ _gitea_expose_uri }}"
_gitea_ssl: true
_gitea_ingress_class: nginx

_gitea_trust_bundle_configmap: ''
2 changes: 2 additions & 0 deletions roles/gitea-ocp/templates/Ingress.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ metadata:
namespace: "{{ _gitea_namespace }}"
labels:
app: "{{ _gitea_name }}"
annotations:
kubernetes.io/ingress.class: {{ _gitea_ingress_class }}
spec:
{% if _gitea_ssl|bool %}
tls:
Expand Down

0 comments on commit 9a500e1

Please sign in to comment.