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

Mw/grocery list #27

Merged
merged 4 commits into from
Mar 5, 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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
.idea/
rollouts-plugin-trafficrouter-consul
consul
testing/resources/kind_config.yaml
testing/resources/kind_config.yaml
testing/values_rollout_init.yaml
testing/values_rollout_https.yaml
2 changes: 1 addition & 1 deletion .go-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.21.6
1.22.0
13 changes: 13 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
package main

import (
"flag"
"fmt"

"github.com/argoproj-labs/rollouts-plugin-trafficrouter-consul/pkg/plugin"

"github.com/argoproj-labs/rollouts-plugin-trafficrouter-consul/pkg/version"
rolloutsPlugin "github.com/argoproj/argo-rollouts/rollout/trafficrouting/plugin/rpc"
goPlugin "github.com/hashicorp/go-plugin"
log "github.com/sirupsen/logrus"
Expand All @@ -22,6 +26,15 @@ var handshakeConfig = goPlugin.HandshakeConfig{
}

func main() {
// Create a flag to print the version of the plugin
// This is useful for debugging and support
versionFlag := flag.Bool("version", false, "Print the version of the plugin")
flag.Parse()
if *versionFlag {
fmt.Println(version.GetHumanVersion())
return
}

logCtx := log.WithFields(log.Fields{"plugin": "trafficrouter"})
log.SetLevel(log.InfoLevel)

Expand Down
14 changes: 7 additions & 7 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,24 @@ version: ## display version
##@ Release
.PHONY: check-env
check-env: ## check env
@printenv | grep "ROLLOUT_PLUGIN"
@printenv | grep "ROLLOUTS_PLUGIN"

.PHONY: prepare-release-script
prepare-release-script: ## Sets the versions, updates changelog to prepare this repository to release
ifndef ROLLOUT_PLUGIN_RELEASE_VERSION
$(error ROLLOUT_PLUGIN_RELEASE_VERSION is required)
ifndef ROLLOUTS_PLUGIN_RELEASE_VERSION
$(error ROLLOUTS_PLUGIN_RELEASE_VERSION is required)
endif
@source $(CURDIR)/build-support/scripts/functions.sh; prepare_release $(CURDIR) $(ROLLOUT_PLUGIN_RELEASE_VERSION) $(ROLLOUT_PLUGIN_PRERELEASE_VERSION); \
@source $(CURDIR)/build-support/scripts/functions.sh; prepare_release $(CURDIR) $(ROLLOUTS_PLUGIN_RELEASE_VERSION) $(ROLLOUTS_PLUGIN_PRERELEASE_VERSION); \

.PHONY: prepare-release
prepare-release: prepare-release-script

.PHONY: prepare-dev
prepare-dev: ## prepare main dev
ifndef ROLLOUT_PLUGIN_NEXT_RELEASE_VERSION
$(error ROLLOUT_PLUGIN_NEXT_RELEASE_VERSION is required)
ifndef ROLLOUTS_PLUGIN_NEXT_RELEASE_VERSION
$(error ROLLOUTS_PLUGIN_NEXT_RELEASE_VERSION is required)
endif
source $(CURDIR)/build-support/scripts/functions.sh; prepare_dev $(CURDIR) $(ROLLOUT_PLUGIN_NEXT_RELEASE_VERSION)
source $(CURDIR)/build-support/scripts/functions.sh; prepare_dev $(CURDIR) $(ROLLOUTS_PLUGIN_NEXT_RELEASE_VERSION)

##@ Help

Expand Down
62 changes: 62 additions & 0 deletions testing/makefile
Original file line number Diff line number Diff line change
@@ -1,66 +1,90 @@
KUBERNETES_VERSION = v1.25.11
CONSUL_K8S_CHART_VERSION = 1.3.1
PLUGIN_DIR= $(shell realpath ../)
IMAGE=hashicorppreview/rollouts-plugin-trafficrouter-consul:0.0-dev
HTTPS_BINARY=https://github.com/argoproj-labs/rollouts-plugin-trafficrouter-sample-nginx/releases/download/v0.0.1/metric-plugin-linux-amd64

#Do Not change
VALUES_INIT_HELM=values_rollout_init.yaml
VALUES_HTTPS_HELM=values_rollout_https.yaml

### TEST VERIFICATION
.PHONY: setup
setup: build-plugin create-kind-config consul-setup argo-setup

# Command for checking how the service is being split by running curl from inside a client pod
.PHONY: splitting-watch
splitting-watch:
./scripts/splitting-watch.sh

.PHONY: rollout-watch
rollout-watch:
kubectl argo rollouts get rollout static-server --watch

# Command used to deploy the canary deployment, will need to be promoted to continue
.PHONY: deploy-canary-v2
deploy-canary-v2:
kubectl apply -f resources/canary_rollout_v2.yaml

# Command used to promote the canary deployment stopped with pause{}
.PHONY: promote
promote:
kubectl argo rollouts promote static-server

.PHONY: undo
undo:
kubectl argo rollouts undo static-server

.PHONY: abort
abort:
kubectl argo rollouts abort static-server

.PHONY: kretryind
retry:
kubectl argo rollouts retry rollout static-server

.PHONY: check-service-splitter
check-service-splitter:
kubectl describe servicesplitters.consul.hashicorp.com

.PHONY: check-service-resolver
check-service-resolver:
kubectl describe serviceresolver.consul.hashicorp.com

### SETUP KIND CLUSTER WITH CONSUL
# consul-setup sets up the kind cluster and deploys the consul helm chart
.PHONY: consul-setup
consul-setup: kind deploy
./scripts/verify-pod-ready.sh consul-server 300; \
./scripts/verify-pod-ready.sh consul-connect-injector 300; \

.PHONY: kind
kind: kind-delete
kind create cluster --image kindest/node:$(KUBERNETES_VERSION) --name=dc1 --config ./resources/kind_config.yaml

.PHONY: add-helm-repo
add-helm-repo:
helm repo add hashicorp https://helm.releases.hashicorp.com

.PHONY: kind-delete
kind-delete:
kind delete cluster --name=dc1

.PHONY: deploy
deploy:
helm repo update; helm install consul hashicorp/consul --version $(CONSUL_K8S_CHART_VERSION) -f values.yaml

# Install Argo
.PHONY: argo-setup
argo-setup: deploy-argo apply-crds

.PHONY: deploy-argo
deploy-argo:
kubectl create namespace argo-rollouts; \
helm install argo-rollouts argo/argo-rollouts -f values_rollout.yaml -n argo-rollouts; \
kubectl apply -f $(PLUGIN_DIR)/yaml/rbac.yaml

.PHONY: apply-crds
apply-crds:
kubectl apply -f resources/proxy_defaults.yaml \
-f resources/serviceaccount.yaml \
Expand All @@ -72,13 +96,51 @@ apply-crds:
-f resources/service_splitter.yaml \
-f resources/canary_rollout.yaml

.PHONY: create-kind-config
create-kind-config:
./scripts/create-kind-config.sh ./resources/kind_config.yaml $(PLUGIN_DIR)/testing

.PHONY: build-plugin
build-plugin:
@cd $(PLUGIN_DIR); CGO_ENABLED=0 GOOS=linux GOARCH=$(TARGETARCH) go build -v -o testing/rollouts-plugin-trafficrouter-consul ./

### RELEASE VERIFICATION
# IMAGE
.PHONY: setup-image
setup-image: consul-setup argo-setup-image

.PHONY: argo-setup-image
argo-setup-image: argo-image-values deploy-argo-image apply-crds

.PHONY: argo-image-values
argo-image-values:
./scripts/create_values_rollout_init_helm.sh ./$(VALUES_INIT_HELM) $(IMAGE)

.PHONY: deploy-argo-image
deploy-argo-image:
kubectl create namespace argo-rollouts; \
helm install argo-rollouts argo/argo-rollouts -f $(VALUES_INIT_HELM) -n argo-rollouts; \
kubectl apply -f $(PLUGIN_DIR)/yaml/rbac.yaml

#HTTPS
.PHONY: setup-https
setup-https: consul-setup argo-setup-https

.PHONY: argo-setup-https
argo-setup-https: argo-https-values deploy-argo-https apply-crds

.PHONY: argo-https-values
argo-https-values:
./scripts/create_values_rollout_https_helm.sh ./$(VALUES_HTTPS_HELM) $(HTTPS_BINARY)

.PHONY: deploy-argo-https
deploy-argo-https:
kubectl create namespace argo-rollouts; \
helm install argo-rollouts argo/argo-rollouts -f $(VALUES_HTTPS_HELM) -n argo-rollouts; \
kubectl apply -f $(PLUGIN_DIR)/yaml/rbac.yaml

## EXTRAS
.PHONY: install-required
install-required:
brew install argoproj/tap/kubectl-argo-rollouts; \
brew install helm; \
Expand Down
35 changes: 35 additions & 0 deletions testing/scripts/create_values_rollout_https_helm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# Check if the correct number of arguments are passed
if [ "$#" -ne 2 ]; then
echo "Usage: $0 helm_file binary"
exit 1
fi

# New host path
helm_file=$1
binary=$2

# Create the YAML structure and write it to kind_config_file
cat << EOF > "$helm_file"
controller:
image:
# -- Registry to use
registry: docker.io
# -- Repository to use
repository: wilko1989/argo-rollouts
# -- Overrides the image tag (default is the chart appVersion)
tag: latest
# -- Image pull policy
pullPolicy: Always
trafficRouterPlugins:
trafficRouterPlugins: |-
- name: "hashicorp/consul"
location: $binary # supports http(s):// urls and file://
volumes:
- name: consul-plugin
emptyDir: {}
volumeMounts:
- name: consul-plugin
mountPath: /plugin-bin/hashicorp
EOF
45 changes: 45 additions & 0 deletions testing/scripts/create_values_rollout_init_helm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

# Check if the correct number of arguments are passed
if [ "$#" -ne 2 ]; then
echo "Usage: $0 helm_file image"
exit 1
fi

# New host path
helm_file=$1
image=$2

# Create the YAML structure and write it to kind_config_file
cat << EOF > "$helm_file"
controller:
image:
# -- Registry to use
registry: docker.io
# -- Repository to use
repository: wilko1989/argo-rollouts
# -- Overrides the image tag (default is the chart appVersion)
tag: latest
# -- Image pull policy
pullPolicy: Always
initContainers:
- name: copy-consul-plugin
image: $image
command: ["/bin/sh", "-c"]
args:
# Copy the binary from the image to the rollout container
- cp /bin/rollouts-plugin-trafficrouter-consul /plugin-bin/hashicorp
volumeMounts:
- name: consul-plugin
mountPath: /plugin-bin/hashicorp
trafficRouterPlugins:
trafficRouterPlugins: |-
- name: "hashicorp/consul"
location: "file:///plugin-bin/hashicorp/rollouts-plugin-trafficrouter-consul"
volumes:
- name: consul-plugin
emptyDir: {}
volumeMounts:
- name: consul-plugin
mountPath: /plugin-bin/hashicorp
EOF
Loading