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

Revert "Avoid e2e test changing tracked files (#1329)" #1365

Merged
merged 1 commit into from
Feb 8, 2024
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 21 additions & 43 deletions .github/actions/gen-install-scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,7 @@

set -xeou pipefail

subdir=${1:-}

target_dir="deploy"
bundle_dir="bundle"
config_dir="config"

function cleanup() {
# Restore original bundle.Dockerfile as needed
cp bundle.Dockerfile "${bundle_dir}/bundle.Dockerfile"
mv bundle.Dockerfile.backup bundle.Dockerfile
}

if [ "${subdir}" != "" ]; then
target_dir+="/${subdir}"
bundle_dir+="/${subdir}"
config_dir+="/${subdir}"
mkdir -p "${target_dir}" "${bundle_dir}"
cp -R config/release "${config_dir}"
cp -R bundle/manifests bundle/metadata "${bundle_dir}/manifests"
cp bundle.Dockerfile bundle.Dockerfile.backup
trap cleanup EXIT
fi

clusterwide_dir="${target_dir}/clusterwide"
namespaced_dir="${target_dir}/namespaced"
crds_dir="${target_dir}/crds"
Expand All @@ -36,59 +14,59 @@ mkdir -p "${crds_dir}"
mkdir -p "${openshift}"

# Generate configuration and save it to `all-in-one`
controller-gen crd:crdVersions=v1,ignoreUnexportedFields=true rbac:roleName=manager-role webhook paths="./pkg/api/..." output:crd:artifacts:config="${config_dir}/crd/bases"
cd "${config_dir}/manager" && kustomize edit set image controller="${INPUT_IMAGE_URL}"
controller-gen crd:crdVersions=v1,ignoreUnexportedFields=true rbac:roleName=manager-role webhook paths="./pkg/api/..." output:crd:artifacts:config=config/crd/bases
cd config/manager && kustomize edit set image controller="${INPUT_IMAGE_URL}"
cd -
./scripts/split_roles_yaml.sh "${subdir}"
./scripts/split_roles_yaml.sh

which kustomize
kustomize version

# all-in-one
kustomize build --load-restrictor LoadRestrictionsNone "${config_dir}/release/${INPUT_ENV}/allinone" > "${target_dir}/all-in-one.yaml"
kustomize build --load-restrictor LoadRestrictionsNone "config/release/${INPUT_ENV}/allinone" > "${target_dir}/all-in-one.yaml"
echo "Created all-in-one config"

# clusterwide
kustomize build --load-restrictor LoadRestrictionsNone "${config_dir}/release/${INPUT_ENV}/clusterwide" > "${clusterwide_dir}/clusterwide-config.yaml"
kustomize build "${config_dir}/crd" > "${clusterwide_dir}/crds.yaml"
kustomize build --load-restrictor LoadRestrictionsNone "config/release/${INPUT_ENV}/clusterwide" > "${clusterwide_dir}/clusterwide-config.yaml"
kustomize build "config/crd" > "${clusterwide_dir}/crds.yaml"
echo "Created clusterwide config"

# base-openshift-namespace-scoped
kustomize build --load-restrictor LoadRestrictionsNone "${config_dir}/release/${INPUT_ENV}/openshift" > "${openshift}/openshift.yaml"
kustomize build "${config_dir}/crd" > "${openshift}/crds.yaml"
kustomize build --load-restrictor LoadRestrictionsNone "config/release/${INPUT_ENV}/openshift" > "${openshift}/openshift.yaml"
kustomize build "config/crd" > "${openshift}/crds.yaml"
echo "Created openshift namespaced config"

# namespaced
kustomize build --load-restrictor LoadRestrictionsNone "${config_dir}/release/${INPUT_ENV}/namespaced" > "${namespaced_dir}/namespaced-config.yaml"
kustomize build "${config_dir}/crd" > "${namespaced_dir}/crds.yaml"
kustomize build --load-restrictor LoadRestrictionsNone "config/release/${INPUT_ENV}/namespaced" > "${namespaced_dir}/namespaced-config.yaml"
kustomize build "config/crd" > "${namespaced_dir}/crds.yaml"
echo "Created namespaced config"

# crds
cp "${config_dir}/crd/bases"/* "${crds_dir}"
cp config/crd/bases/* "${crds_dir}"

# CSV bundle
operator-sdk generate kustomize manifests -q --apis-dir=pkg/api
# get the current version so we could put it into the "replaces:"
current_version=$(yq e '.metadata.name' "${bundle_dir}/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml")
current_version="$(yq e '.metadata.name' bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml)"

# We pass the version only for non-dev deployments (it's ok to have "0.0.0" for dev)
channel="stable"
if [[ "${INPUT_ENV}" == "dev" ]]; then
echo "build dev purpose"
kustomize build --load-restrictor LoadRestrictionsNone "${config_dir}/manifests" |
operator-sdk generate bundle -q --overwrite --default-channel="${channel}" --channels="${channel}" --output-dir "${bundle_dir}"
kustomize build --load-restrictor LoadRestrictionsNone config/manifests |
operator-sdk generate bundle -q --overwrite --default-channel="${channel}" --channels="${channel}"
else
echo "build release version"
echo "${INPUT_IMAGE_URL}"
kustomize build --load-restrictor LoadRestrictionsNone "${config_dir}/manifests" |
operator-sdk generate bundle -q --overwrite --version "${INPUT_VERSION}" --default-channel="${channel}" --channels="${channel}" --output-dir "${bundle_dir}"
kustomize build --load-restrictor LoadRestrictionsNone config/manifests |
operator-sdk generate bundle -q --overwrite --version "${INPUT_VERSION}" --default-channel="${channel}" --channels="${channel}"
# add replaces
awk '!/replaces:/' "${bundle_dir}/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml" > tmp && mv tmp "${bundle_dir}/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml"
echo " replaces: $current_version" >> "${bundle_dir}/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml"
awk '!/replaces:/' bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml > tmp && mv tmp bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml
echo " replaces: $current_version" >> bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml
# Add WATCH_NAMESPACE env parameter
value="metadata.annotations['olm.targetNamespaces']" yq e -i '.spec.install.spec.deployments[0].spec.template.spec.containers[0].env[2] |= {"name": "WATCH_NAMESPACE", "valueFrom": {"fieldRef": {"fieldPath": env(value)}}}' "${bundle_dir}/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml"
# Add containerImage to "${bundle_dir}/manifests/" csv. containerImage - The full location (registry, repository, name and tag) of the operator image
yq e -i ".metadata.annotations.containerImage=\"${INPUT_IMAGE_URL}\"" "${bundle_dir}/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml"
value="metadata.annotations['olm.targetNamespaces']" yq e -i '.spec.install.spec.deployments[0].spec.template.spec.containers[0].env[2] |= {"name": "WATCH_NAMESPACE", "valueFrom": {"fieldRef": {"fieldPath": env(value)}}}' bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml
# Add containerImage to bundle/manifests/ csv. containerImage - The full location (registry, repository, name and tag) of the operator image
yq e -i ".metadata.annotations.containerImage=\"${INPUT_IMAGE_URL}\"" bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml
fi

# add additional LABELs to bundle.Docker file
Expand Down
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ node_modules
tmp/

# ready to work samples
deploy

# e2e work files
config/e2e
bundle/e2e
deploy/

# ignore tool binaries
tools/clean/clean
Expand Down
8 changes: 4 additions & 4 deletions scripts/e2e_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ export INPUT_IMAGE_URL="${image}"
export INPUT_ENV=dev

if [[ "${build}" == "true" ]]; then
./.github/actions/gen-install-scripts/entrypoint.sh e2e
awk '{gsub(/cloud.mongodb.com/, "cloud-qa.mongodb.com", $0); print}' bundle/e2e/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml > tmp && mv tmp bundle/e2e/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml
./.github/actions/gen-install-scripts/entrypoint.sh
awk '{gsub(/cloud.mongodb.com/, "cloud-qa.mongodb.com", $0); print}' bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml > tmp && mv tmp bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml

docker build -t "${image}" .
docker push "${image}"

#bundles
docker build -f bundle/e2e/bundle.Dockerfile -t "${bundle_image}" .
docker build -f bundle.Dockerfile -t "${bundle_image}" .
docker push "${bundle_image}"
fi

kubectl apply -f deploy/e2e/crds
kubectl apply -f deploy/crds

export MCLI_OPS_MANAGER_URL="https://cloud-qa.mongodb.com/"
export MCLI_PUBLIC_API_KEY="${public_key}"
Expand Down
21 changes: 7 additions & 14 deletions scripts/split_roles_yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,13 @@

set -eou pipefail

subdir=${1:-}

config_dir="config"
if [ "${subdir}" != "" ]; then
config_dir+="/${subdir}"
fi

# This is the script that allows to avoid the restrictions from the controller-gen tool that puts both Role and ClusterRole
# to the same role.yaml file (and kustomize doesn't provide an easy way to use only a single resource from file as a base)
# So we simply split the '"${config_dir}rbac/roles.yaml' file into two new files
if [[ -f "${config_dir}/rbac/role.yaml" ]]; then
awk '/---/{f="xx0"int(++i);} {if(NF!=0)print > f};' "${config_dir}/rbac/role.yaml"
# csplit "${config_dir}/rbac/role.yaml" '/---/' '{*}' &> /dev/null - infinite repetition '{*}' is not working on BSD/OSx
mv xx01 "${config_dir}/rbac/clusterwide/role.yaml"
mv xx02 "${config_dir}/rbac/namespaced/role.yaml"
rm "${config_dir}/rbac/role.yaml"
# So we simply split the 'config/rbac/roles.yaml' file into two new files
if [[ -f config/rbac/role.yaml ]]; then
awk '/---/{f="xx0"int(++i);} {if(NF!=0)print > f};' config/rbac/role.yaml
# csplit config/rbac/role.yaml '/---/' '{*}' &> /dev/null - infinite repetition '{*}' is not working on BSD/OSx
mv xx01 config/rbac/clusterwide/role.yaml
mv xx02 config/rbac/namespaced/role.yaml
rm config/rbac/role.yaml
fi
12 changes: 6 additions & 6 deletions test/helper/e2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package config
const (

// Kubernetes configuration samples for users in deploy directory
DefaultDeployConfig = "../../deploy/e2e/" // Released generated files
DefaultClusterWideCRDConfig = "../../deploy/e2e/clusterwide/crds.yaml"
DefaultClusterWideOperatorConfig = "../../deploy/e2e/clusterwide/clusterwide-config.yaml"
DefaultNamespacedCRDConfig = "../../deploy/e2e/namespaced/crds.yaml"
DefaultNamespacedOperatorConfig = "../../deploy/e2e/namespaced/namespaced-config.yaml"
DefaultDeployConfig = "../../deploy/" // Released generated files
DefaultClusterWideCRDConfig = "../../deploy/clusterwide/crds.yaml"
DefaultClusterWideOperatorConfig = "../../deploy/clusterwide/clusterwide-config.yaml"
DefaultNamespacedCRDConfig = "../../deploy/namespaced/crds.yaml"
DefaultNamespacedOperatorConfig = "../../deploy/namespaced/namespaced-config.yaml"

// Default names/path for tests coordinates
DataGenFolder = "data/gen" // for generated configs
Expand Down Expand Up @@ -41,5 +41,5 @@ const (
AzureRegionEU = "northeurope"

// GCP
FileNameSAGCP = "../../output/gcp_service_account.json"
FileNameSAGCP = "gcp_service_account.json"
)
Loading