Skip to content

Backport of Tests: Fix/improve tests with Restricted PSA enforcement into release/1.0.x#2935

Merged
missylbytes merged 1 commit intorelease/1.0.xfrom
backport/pglass/fix-kind-psa-use-app-namespace/normally-strong-louse
Sep 11, 2023
Merged

Backport of Tests: Fix/improve tests with Restricted PSA enforcement into release/1.0.x#2935
missylbytes merged 1 commit intorelease/1.0.xfrom
backport/pglass/fix-kind-psa-use-app-namespace/normally-strong-louse

Conversation

@hc-github-team-consul-core
Copy link
Copy Markdown
Collaborator

@hc-github-team-consul-core hc-github-team-consul-core commented Sep 11, 2023

Backport

This PR is auto-generated from #2780 to be assessed for backporting due to the inclusion of the label backport/1.0.x.

🚨

Warning automatic cherry-pick of commits failed. If the first commit failed,
you will see a blank no-op commit below. If at least one commit succeeded, you
will see the cherry-picked commits up to, not including, the commit where
the merge conflict occurred.

The person who merged in the original PR is:
@missylbytes
This person should manually cherry-pick the original PR into a new backport PR,
and close this one when the manual backport PR is merged in.

merge conflict error: POST https://api.github.com/repos/hashicorp/consul-k8s/merges: 409 Merge conflict []

The below text is copied from the body of the original PR.


Changes proposed in this PR:

In the acceptance tests:

  • fix: Deploy apps to a separate namespace in ConnectHelper when not on OpenShift and -enable-restricted-psa-enforcement is set
  • improvement: Auto-configure the restricted PSA enforcement label when -enable-restricted-psa-enforcement is set

How I've tested this PR:

Run the following commands:

$ make kind-cni
$ ./test-psa-kind.sh -cni

Where the ./test-psa-kind.sh script is the following

Test script
#!/usr/bin/env bash

set -euo pipefail

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

export CONSUL_LICENSE=$(cat ~/.consul-ent-license)
export CONSUL_ENT_LICENSE=$CONSUL_LICENSE

# Cleanup old namespaces
# for context in $(kubectl config get-contexts -o name | grep '^kind-') ; do
for context in kind-dc1 kind-dc2 ; do
    kubectl --context $context get ns \
		| grep ^acceptance | awk '{print $1}' \
		| xargs -n 1 -I '{}' kubectl --context $context delete ns '{}' || true
done

EXTRA_FLAGS=""

while [[ $# -gt 0 ]]; do
    case $1 in
        -tproxy)
            EXTRA_FLAGS+=" -enable-transparent-proxy"
            shift;
            ;;
        -cni)
            EXTRA_FLAGS+=" -enable-cni -enable-transparent-proxy"
            shift;
            ;;
        *)
            echo "Unrecognized argument: '$1'"
            exit 1
    esac
done

function runtest() {
    local testdir=$1
    local runtest=$2

    if [ -n "$runtest" ]; then
        runtest="-run $runtest"
    fi

    # Create consul namespaces with restricted PSA enformcement.
    set -xeuo pipefail

    local ns_base="acceptance-$1-$RANDOM"
    local contexts=""
    local namespaces=""
    #for context in $(kubectl config get-contexts -o name | grep '^kind-') ; do
    for context in kind-dc1 kind-dc2 ; do
        local consul_namespace="${ns_base}-$context"
        if [ -n "$contexts" ]; then
            contexts+=","
            namespaces+=","
        fi
        contexts+="$context"
        namespaces+="$consul_namespace"
    done

    # Grab the default image versions from the helm values.
    imageK8S=$(cat ../charts/consul/values.yaml | yq -r '.global.imageK8S')
    imageConsul=$(cat ../charts/consul/values.yaml | yq -r '.global.image' | sed 's/consul:/consul-enterprise:/')
    imageDataplane=$(cat ../charts/consul/values.yaml | yq -r '.global.imageConsulDataplane')

    cd "${SCRIPT_DIR}/tests/$testdir"
    rm -rf ./_debug
    mkdir ./_debug
    go test  -v -p 1 -timeout 15m -failfast \
        -consul-k8s-image "$imageK8S" \
        -consul-image "$imageConsul" \
        -consul-dataplane-image "$imageDataplane" \
        -debug-directory ./_debug \
        -enable-enterprise \
        -kube-contexts "$contexts" \
        -kube-namespaces "$namespaces" \
        -enable-multi-cluster -use-kind \
        -enable-restricted-psa-enforcement \
        $EXTRA_FLAGS $runtest \
        ./...
}

runtest "connect" 'TestConnectInject$'

How I expect reviewers to test this PR:

👀 or try to run the tests if you want

Checklist:


Overview of commits

@hc-github-team-consul-core hc-github-team-consul-core force-pushed the backport/pglass/fix-kind-psa-use-app-namespace/normally-strong-louse branch 2 times, most recently from db1be3c to bf9fae0 Compare September 11, 2023 14:44
@hashicorp-cla
Copy link
Copy Markdown

hashicorp-cla commented Sep 11, 2023

CLA assistant check
All committers have signed the CLA.

@missylbytes missylbytes marked this pull request as ready for review September 11, 2023 15:33
* tests: Respect UseAppNamespace in ConnectHelper

* tests: Auto-configure restricted PSA enforcement when enabled

---------

Co-authored-by: Paul Glass <pglass@hashicorp.com>
@missylbytes missylbytes force-pushed the backport/pglass/fix-kind-psa-use-app-namespace/normally-strong-louse branch from 201165c to 09a9f70 Compare September 11, 2023 15:34
@missylbytes missylbytes merged commit 1d123c3 into release/1.0.x Sep 11, 2023
@missylbytes missylbytes deleted the backport/pglass/fix-kind-psa-use-app-namespace/normally-strong-louse branch September 11, 2023 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants