-
Notifications
You must be signed in to change notification settings - Fork 75
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
Add nginx ingress addon #139
Draft
berkayoz
wants to merge
4
commits into
main
Choose a base branch
from
MK-1083/nginx-ingress
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
source $SNAP/actions/common/utils.sh | ||
CURRENT_DIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) | ||
|
||
NAMESPACE="nginx-ingress" | ||
KUBECTL="$SNAP/microk8s-kubectl.wrapper" | ||
HELM="${SNAP}/microk8s-helm3.wrapper" | ||
echo "Disabling NGINX ingress" | ||
|
||
# unload the the manifests | ||
$HELM uninstall nginx-ingress -n $NAMESPACE > /dev/null 2>&1 | ||
$KUBECTL delete secret nginx-regcred -n $NAMESPACE > /dev/null 2>&1 || true | ||
$KUBECTL delete namespace $NAMESPACE | ||
|
||
echo "NGINX ingress is disabled" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
source $SNAP/actions/common/utils.sh | ||
CURRENT_DIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) | ||
source $CURRENT_DIR/../common/utils.sh | ||
|
||
NAMESPACE="nginx-ingress" | ||
CHART_VERSION="0.16.2" | ||
KUBECTL="$SNAP/microk8s-kubectl.wrapper" | ||
HELM="${SNAP}/microk8s-helm3.wrapper" | ||
|
||
TEMP=$(getopt -o "h" \ | ||
--long help,tls-secret:,plus-token:,values: \ | ||
-n "$(basename "$0")" -- "$@") | ||
|
||
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi | ||
|
||
eval set -- "$TEMP" | ||
|
||
CERT_SECRET="${CERT_SECRET:-}" | ||
PLUS_TOKEN="${PLUS_TOKEN:-}" | ||
NGINX_VALUES="${NGINX_VALUES:-}" | ||
|
||
while true; do | ||
case "$1" in | ||
--tls-secret ) CERT_SECRET="$2"; shift 2 ;; | ||
--plus-token ) PLUS_TOKEN="$2"; shift 2 ;; | ||
--values ) NGINX_VALUES="$2"; shift 2 ;; | ||
-h | --help ) | ||
prog=$(basename -s.wrapper "$0") | ||
echo "Usage: $prog [options...]" | ||
echo " --tls-secret <secret> TLS Secret that will be used by the controller" | ||
echo " Example: namespace/secret_name" | ||
echo " --plus-token <token> JWT Image Pull Token for Nginx Plus" | ||
echo " --values <distro> Values file to override for the nginx helm chart" | ||
echo | ||
exit ;; | ||
-- ) shift; break ;; | ||
* ) break ;; | ||
esac | ||
done | ||
|
||
echo "Enabling NGINX ingress" | ||
|
||
$HELM repo add nginx-stable https://helm.nginx.com/stable | ||
$HELM repo update | ||
|
||
HELM_OPTS= | ||
if [ -n "${CERT_SECRET}" ]; then | ||
HELM_OPTS+="--set controller.defaultTLS.secret=${CERT_SECRET} " | ||
fi | ||
|
||
if [ -n "${NGINX_VALUES}" ]; then | ||
HELM_OPTS+="--values ${NGINX_VALUES} " | ||
fi | ||
|
||
if [ -n "${PLUS_TOKEN}" ]; then | ||
$KUBECTL create namespace $NAMESPACE | ||
$KUBECTL create secret docker-registry nginx-regcred --docker-server=private-registry.nginx.com --docker-username=$PLUS_TOKEN --docker-password=none -n $NAMESPACE | ||
|
||
$HELM upgrade --install nginx-ingress nginx-stable/nginx-ingress \ | ||
--namespace $NAMESPACE \ | ||
--set controller.config.entries.external-status-address="127.0.0.1" \ | ||
--set controller.hostNetwork=true \ | ||
--set controller.image.repository=private-registry.nginx.com/nginx-ic/nginx-plus-ingress \ | ||
--set controller.serviceAccount.imagePullSecretName=nginx-regcred \ | ||
--set controller.nginxplus=true \ | ||
--version $CHART_VERSION \ | ||
${HELM_OPTS} | ||
else | ||
$HELM upgrade --install nginx-ingress nginx-stable/nginx-ingress \ | ||
--namespace $NAMESPACE --create-namespace \ | ||
--set controller.config.entries.external-status-address="127.0.0.1" \ | ||
--set controller.hostNetwork=true \ | ||
--version $CHART_VERSION \ | ||
${HELM_OPTS} | ||
fi | ||
|
||
echo "NGINX ingress is enabled" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import time | ||
import os | ||
|
||
import requests | ||
|
||
from utils import ( | ||
kubectl, | ||
microk8s_disable, | ||
microk8s_enable, | ||
update_yaml_with_arch, | ||
wait_for_pod_state, | ||
) | ||
|
||
|
||
class TestNginxIngress(object): | ||
def test_nginx_ingress(self): | ||
""" | ||
Sets up and validates nginx-ingress. | ||
""" | ||
print("Enabling nginx-ingress") | ||
microk8s_enable("nginx-ingress") | ||
print("Validating nginx-ingress") | ||
self.validate_nginx_ingress() | ||
print("Disabling nginx-ingress") | ||
microk8s_disable("nginx-ingress") | ||
|
||
def common_ingress(self): | ||
""" | ||
Perform the Ingress validations that are common for all | ||
the Ingress controllers. | ||
""" | ||
attempt = 50 | ||
while attempt >= 0: | ||
output = kubectl("get ing") | ||
if "microbot.127.0.0.1.nip.io" in output: | ||
break | ||
time.sleep(5) | ||
attempt -= 1 | ||
assert "microbot.127.0.0.1.nip.io" in output | ||
|
||
service_ok = False | ||
attempt = 50 | ||
while attempt >= 0: | ||
try: | ||
resp = requests.get("http://microbot.127.0.0.1.nip.io/") | ||
if resp.status_code == 200 and "microbot.png" in resp.content.decode( | ||
"utf-8" | ||
): | ||
service_ok = True | ||
break | ||
except requests.RequestException: | ||
time.sleep(5) | ||
attempt -= 1 | ||
|
||
assert service_ok | ||
|
||
def validate_nginx_ingress(self): | ||
""" | ||
Validate nginx-ingress | ||
""" | ||
kubectl( | ||
"annotate ingressclass nginx ingressclass.kubernetes.io/is-default-class=true" | ||
) | ||
wait_for_pod_state( | ||
"", "nginx-ingress", "running", label="app=nginx-ingress-nginx-ingress" | ||
) | ||
|
||
here = os.path.dirname(os.path.abspath(__file__)) | ||
manifest = os.path.join(here, "templates", "ingress.yaml") | ||
update_yaml_with_arch(manifest) | ||
kubectl("apply -f {}".format(manifest)) | ||
wait_for_pod_state("", "default", "running", label="app=microbot") | ||
|
||
self.common_ingress() | ||
|
||
kubectl("delete -f {}".format(manifest)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.