Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/go_modules/github.com/hashicorp…
Browse files Browse the repository at this point in the history
…/go-multierror-1.1.1
  • Loading branch information
aslakknutsen authored Mar 16, 2021
2 parents 22e6ffe + 2bd4928 commit b365862
Show file tree
Hide file tree
Showing 30 changed files with 257 additions and 150 deletions.
12 changes: 12 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,18 @@ jobs:
sleep 10
done
echo "Istio enabled"
echo "Installing tekton"
kubectl apply -f https://storage.googleapis.com/tekton-releases/pipeline/previous/v0.16.3/release.yaml
sleep 10
n=0
until [ $n -ge 10 ]
do
(kubectl get pods --namespace tekton-pipelines | grep -z "Running") && break
n=$[$n+1]
sleep 10
done
echo "Tekton installed"
- run:
name: "Run end-to-end tests"
command: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/golangci_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
env:
REPOSITORY: ${{ github.repository }}
steps:
- name: Set up Go 1.15.5
- name: Set up Go env
uses: actions/setup-go@v2
with:
go-version: 1.15.5
go-version: 1.15.8
- uses: actions/checkout@v2
with:
fetch-depth: 1
Expand Down
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@ issues:
- errcheck
- dupl
- gosec
- path: _suite_test\.go
linters:
- unused

47 changes: 35 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $(shell mkdir -p $(PROJECT_DIR)/bin/)
export PROJECT_DIR
export GO111MODULE:=on
BUILD_DIR:=$(PROJECT_DIR)/build
BINARY_DIR:=$(PROJECT_DIR)/dist
DIST_DIR:=$(PROJECT_DIR)/dist
BINARY_NAME:=ike
TEST_BINARY_NAME:=test-service
TPL_BINARY_NAME:=tpl
Expand Down Expand Up @@ -97,7 +97,7 @@ endif
build-ci: deps tools format compile test # Like 'all', but without linter which is executed as separated PR check

.PHONY: compile
compile: deps generate format $(BINARY_DIR)/$(BINARY_NAME) ## Compiles binaries
compile: deps generate format $(DIST_DIR)/$(BINARY_NAME) ## Compiles binaries

.PHONY: test
test: generate ## Runs tests
Expand All @@ -111,7 +111,7 @@ test-e2e: compile ## Runs end-to-end tests

.PHONY: clean
clean: ## Removes build artifacts
rm -rf $(BINARY_DIR) $(PROJECT_DIR)/bin/ vendor/ bundle/
rm -rf $(DIST_DIR) $(PROJECT_DIR)/bin/ vendor/ bundle/

.PHONY: deps
deps: ## Fetches all dependencies
Expand Down Expand Up @@ -152,14 +152,14 @@ generate: tools $(PROJECT_DIR)/$(ASSETS) $(PROJECT_DIR)/api ## Generates k8s man
version:
@echo $(IKE_VERSION)

$(BINARY_DIR):
$(DIST_DIR):
[ -d $@ ] || mkdir -p $@

$(BINARY_DIR)/$(BINARY_NAME): $(BINARY_DIR) $(SRCS)
$(DIST_DIR)/$(BINARY_NAME): $(DIST_DIR) $(SRCS)
$(call header,"Compiling... carry on!")
${GOBUILD} go build -ldflags ${LDFLAGS} -o $@ ./cmd/$(BINARY_NAME)/

$(BINARY_DIR)/$(TEST_BINARY_NAME): $(BINARY_DIR) $(SRCS) test/cmd/test-service/html.go
$(DIST_DIR)/$(TEST_BINARY_NAME): $(DIST_DIR) $(SRCS) test/cmd/test-service/html.go
$(call header,"Compiling test service... carry on!")
${GOBUILD} go build -ldflags ${LDFLAGS} -o $@ ./test/cmd/$(TEST_BINARY_NAME)/

Expand All @@ -172,9 +172,9 @@ test/cmd/test-service/html.go: test/cmd/test-service/assets/index.html
go-bindata -o test/cmd/test-service/html.go -pkg main -prefix test/cmd/test-service/assets test/cmd/test-service/assets/*

.PHONY: compile-test-service
compile-test-service: test/cmd/test-service/html.go test/cmd/test-service/main.pb.go $(BINARY_DIR)/$(TEST_BINARY_NAME)
compile-test-service: test/cmd/test-service/html.go test/cmd/test-service/main.pb.go $(DIST_DIR)/$(TEST_BINARY_NAME)

$(BINARY_DIR)/$(TPL_BINARY_NAME): $(BINARY_DIR) $(SRCS)
$(DIST_DIR)/$(TPL_BINARY_NAME): $(DIST_DIR) $(SRCS)
$(call header,"Compiling tpl processor... carry on!")
${GOBUILD} go build -ldflags ${LDFLAGS} -o $@ ./cmd/$(TPL_BINARY_NAME)/

Expand Down Expand Up @@ -263,13 +263,15 @@ IKE_IMAGE_TAG?=$(IKE_VERSION)
IKE_TEST_IMAGE_NAME?=$(IKE_IMAGE_NAME)-test
IKE_TEST_PREPARED_IMAGE_NAME?=$(IKE_TEST_IMAGE_NAME)-prepared
IKE_TEST_PREPARED_NAME?=prepared-image
IKE_IMAGE=${IKE_DOCKER_REGISTRY}\/${IKE_DOCKER_REPOSITORY}\/${IKE_IMAGE_NAME}:${IKE_IMAGE_TAG}

export IKE_DOCKER_REGISTRY
export IKE_DOCKER_REPOSITORY
export IKE_DOCKER_DEV_REPOSITORY
export IKE_IMAGE_NAME
export IKE_IMAGE_TAG
export IKE_VERSION
export IKE_IMAGE

.PHONY: docker-build
docker-build: GOOS=linux
Expand All @@ -287,7 +289,7 @@ docker-build: compile ## Builds the docker image
--label "org.opencontainers.image.created=$(shell date -u +%F\ %T%z)" \
--network=host \
-t $(IKE_DOCKER_REGISTRY)/$(IKE_DOCKER_REPOSITORY)/$(IKE_IMAGE_NAME):$(IKE_IMAGE_TAG) \
-f $(BUILD_DIR)/Dockerfile $(BINARY_DIR)
-f $(BUILD_DIR)/Dockerfile $(DIST_DIR)
$(IMG_BUILDER) tag \
$(IKE_DOCKER_REGISTRY)/$(IKE_DOCKER_REPOSITORY)/$(IKE_IMAGE_NAME):$(IKE_IMAGE_TAG) \
$(IKE_DOCKER_REGISTRY)/$(IKE_DOCKER_REPOSITORY)/$(IKE_IMAGE_NAME):latest
Expand All @@ -303,7 +305,7 @@ docker-push--%:
$(IMG_BUILDER) push $(IKE_DOCKER_REGISTRY)/$(IKE_DOCKER_REPOSITORY)/$(IKE_IMAGE_NAME):$(image_tag)

.PHONY: docker-build-test
docker-build-test: $(BINARY_DIR)/$(TEST_BINARY_NAME)
docker-build-test: $(DIST_DIR)/$(TEST_BINARY_NAME)
$(call header,"Building docker image $(IKE_TEST_IMAGE_NAME)")
$(IMG_BUILDER) build \
--no-cache \
Expand All @@ -318,7 +320,7 @@ docker-build-test: $(BINARY_DIR)/$(TEST_BINARY_NAME)
--label "org.opencontainers.image.created=$(shell date -u +%F\ %T%z)" \
--network=host \
--tag $(IKE_DOCKER_REGISTRY)/$(IKE_DOCKER_DEV_REPOSITORY)/$(IKE_TEST_IMAGE_NAME):$(IKE_IMAGE_TAG) \
-f $(BUILD_DIR)/DockerfileTest $(BINARY_DIR)
-f $(BUILD_DIR)/DockerfileTest $(DIST_DIR)

$(IMG_BUILDER) tag \
$(IKE_DOCKER_REGISTRY)/$(IKE_DOCKER_DEV_REPOSITORY)/$(IKE_TEST_IMAGE_NAME):$(IKE_IMAGE_TAG) \
Expand Down Expand Up @@ -347,7 +349,7 @@ docker-build-test-prepared:
--label "org.opencontainers.image.created=$(shell date -u +%F\ %T%z)" \
--network=host \
--tag $(IKE_DOCKER_REGISTRY)/$(IKE_DOCKER_DEV_REPOSITORY)/$(IKE_TEST_PREPARED_IMAGE_NAME)-$(IKE_TEST_PREPARED_NAME):$(IKE_IMAGE_TAG) \
-f $(BUILD_DIR)/DockerfileTestPrepared $(BINARY_DIR)
-f $(BUILD_DIR)/DockerfileTestPrepared $(DIST_DIR)

$(IMG_BUILDER) tag \
$(IKE_DOCKER_REGISTRY)/$(IKE_DOCKER_DEV_REPOSITORY)/$(IKE_TEST_PREPARED_IMAGE_NAME)-$(IKE_TEST_PREPARED_NAME):$(IKE_IMAGE_TAG) \
Expand Down Expand Up @@ -424,10 +426,31 @@ bundle-publish: ## Open up a PR to the Operator Hub community catalog
##@ Tekton tasks
# ##########################################################################

.PHONY: tekton-deploy
tekton-deploy: ## Deploy the Tekton tasks
sed "s/released-image/${IKE_IMAGE}/g" "$(PROJECT_DIR)/integration/tekton/tasks/ike-create/ike-create.yaml" | $(k8s) apply -f - -n $(TEST_NAMESPACE)
sed "s/released-image/${IKE_IMAGE}/g" "$(PROJECT_DIR)/integration/tekton/tasks/ike-session-url/ike-session-url.yaml" | $(k8s) apply -f - -n $(TEST_NAMESPACE)
sed "s/released-image/${IKE_IMAGE}/g" "$(PROJECT_DIR)/integration/tekton/tasks/ike-delete/ike-delete.yaml" | $(k8s) apply -f - -n $(TEST_NAMESPACE)

.PHONY: tekton-undeploy
tekton-undeploy: ## UnDeploy the Tekton tasks
$(k8s) delete -n $(TEST_NAMESPACE) -f "$(PROJECT_DIR)/integration/tekton/tasks/ike-create/ike-create.yaml" || true
$(k8s) delete -n $(TEST_NAMESPACE) -f "$(PROJECT_DIR)/integration/tekton/tasks/ike-session-url/ike-session-url.yaml" || true
$(k8s) delete -n $(TEST_NAMESPACE) -f "$(PROJECT_DIR)/integration/tekton/tasks/ike-delete/ike-delete.yaml" || true

TEST_SESSION_NAME?=test-session
IKE_TEST_PREPARED_IMG:=$(IKE_DOCKER_REGISTRY)/$(IKE_DOCKER_DEV_REPOSITORY)/$(IKE_TEST_PREPARED_IMAGE_NAME)-$(IKE_TEST_PREPARED_NAME):$(IKE_IMAGE_TAG)

tekton-test-%: $(PROJECT_DIR)/bin/yq ## Run a Tekton tasks for test purpose
$(eval task:=$(subst tekton-test-,,$@))
@yq e '.spec.params[] | select(.name=="session") | .value="${TEST_SESSION_NAME}", .spec.params[] | select(.name=="route") | .value="header:x-test-suite=smoke", .spec.params[] | select(.name=="image") | .value="${IKE_TEST_PREPARED_IMG}", . ' $(PROJECT_DIR)/integration/tekton/tasks/$(task)/samples/$(task).yaml \
| awk '/apiVersion:/,0 {print $1}' | $(k8s) apply -f - -n ${TEST_NAMESPACE}

.PHONY: tekton-publish
tekton-publish: ## Prepares Tekton tasks for release and opens a PR on the Tekton Hub
./scripts/release/tektoncatalog.sh


# ##########################################################################
## Istio-workspace sample project deployment
# ##########################################################################
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/integration/tekton/overview.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ You can use Istio Workspace to prepare special routes from a CI system, e.g. per
PR to test/preview the changes before merging.

The Istio Workspace Tekton tasks wraps the Istio Workspace CLI into a Tekton Task
for easy usage witthin the Tekton/Openshift Pipelines CI system.
for easy usage within the Tekton/Openshift Pipelines CI system.

== Tasks

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ include::cmd:yq[args="e '.spec.results' -P -j -I4 ike-create.yaml | jq -r '. | m

=== Usage

include::cmd:yq[args="e '{\"params\": .params}' -I2 samples/ike-create.yaml", cwd="$PROJECT_DIR/integration/tekton/tasks/ike-create",block=true,format=yaml]
include::cmd:yq[args="e '{\"params\": .spec.params}' -I2 samples/ike-create.yaml", cwd="$PROJECT_DIR/integration/tekton/tasks/ike-create",block=true,format=yaml]
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ include::cmd:yq[args="e '.spec.results' -P -j -I4 ike-delete.yaml | jq -r '. | m

=== Usage

include::cmd:yq[args="e '{\"params\": .params}' -I2 samples/ike-delete.yaml", cwd="$PROJECT_DIR/integration/tekton/tasks/ike-delete",block=true,format=yaml]
include::cmd:yq[args="e '{\"params\": .spec.params}' -I2 samples/ike-delete.yaml", cwd="$PROJECT_DIR/integration/tekton/tasks/ike-delete",block=true,format=yaml]
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ include::cmd:yq[args="e '.spec.results' -P -j -I4 ike-session-url.yaml | jq -r '

=== Usage

include::cmd:yq[args="e '{\"params\": .params}' -I2 samples/ike-session-url.yaml", cwd="$PROJECT_DIR/integration/tekton/tasks/ike-session-url",block=true,format=yaml]
include::cmd:yq[args="e '{\"params\": .spec.params}' -I2 samples/ike-session-url.yaml", cwd="$PROJECT_DIR/integration/tekton/tasks/ike-session-url",block=true,format=yaml]
30 changes: 30 additions & 0 deletions e2e/infra/tekton.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package infra

import (
"strings"

"github.com/onsi/ginkgo"

"github.com/maistra/istio-workspace/test/shell"
)

// TaskIsDone checks if given task has succeeded.
func TaskIsDone(ns, taskName string) func() bool {
return func() bool {
taskRunStatus := shell.ExecuteInDir(".", "kubectl", "get", "taskruns", taskName, "-n", ns, "-o", "jsonpath='{.status.conditions[?(.type==\"Succeeded\")].reason}'")
<-taskRunStatus.Done()
status := strings.Join(taskRunStatus.Status().Stdout, "")
if strings.Contains(status, "Failed") {
<-shell.ExecuteInDir(".", "kubectl", "get", "taskruns", taskName, "-n", ns, "-o", "yaml").Done()
ginkgo.Fail("Expected " + taskName + " to succeed")
}
return strings.Contains(status, "Succeeded")
}
}

// TaskResult returns value of given result variable for defined Task.
func TaskResult(ns, taskName, key string) string {
taskResultStatus := shell.ExecuteInDir(".", "kubectl", "get", "taskruns", taskName, "-n", ns, "-o", "jsonpath={.status.taskResults[?(.name==\""+key+"\")].value}")
<-taskResultStatus.Done()
return strings.Join(taskResultStatus.Status().Stdout, "")
}
1 change: 1 addition & 0 deletions e2e/install_mode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ var _ = Describe("Operator installation", func() {

VerifyWatchList(namespaces...)
})

It("AllNamespace", func() {
namespaces = append(namespaces, generateNamespaceName(), generateNamespaceName())
CreateNamespace()
Expand Down
54 changes: 49 additions & 5 deletions e2e/smoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,57 @@ var _ = Describe("Smoke End To End Tests - against OpenShift Cluster with Istio
})

})

Context("verify external integrations", func() {

Context("Tekton", func() {

BeforeEach(func() {
scenario = "scenario-1"
})

It("should create, get, and delete", func() {
defer test.TemporaryEnvVars("TEST_NAMESPACE", namespace, "TEST_SESSION_NAME", sessionName)()

host := sessionName + "." + GetGatewayHost(namespace)

<-testshell.ExecuteInProjectRoot("make tekton-deploy").Done()

EnsureAllDeploymentPodsAreReady(namespace)
EnsureProdRouteIsReachable(namespace, ContainSubstring("ratings-v1"), Not(ContainSubstring(PreparedImageV1)))

<-testshell.ExecuteInProjectRoot("make tekton-test-ike-create").Done()
Eventually(TaskIsDone(namespace, "ike-create-run"), 5*time.Minute, 5*time.Second).Should(BeTrue())
Expect(TaskResult(namespace, "ike-create-run", "url")).To(Equal(host))

// verify session url
<-testshell.ExecuteInProjectRoot("make tekton-test-ike-session-url").Done()
Eventually(TaskIsDone(namespace, "ike-session-url-run"), 5*time.Minute, 5*time.Second).Should(BeTrue())
Expect(TaskResult(namespace, "ike-session-url-run", "url")).To(Equal(host))

// ensure the new service is running
EnsureAllDeploymentPodsAreReady(namespace)

// check original response
EnsureSessionRouteIsReachable(namespace, sessionName, ContainSubstring(PreparedImageV1), Not(ContainSubstring("ratings-v1")))

// but also check if prod is intact
EnsureProdRouteIsReachable(namespace, ContainSubstring("ratings-v1"), Not(ContainSubstring(PreparedImageV1)))

<-testshell.ExecuteInProjectRoot("make tekton-test-ike-delete").Done()
Eventually(TaskIsDone(namespace, "ike-delete-run"), 5*time.Minute, 5*time.Second).Should(BeTrue())

// check original response
EnsureSessionRouteIsNotReachable(namespace, sessionName, ContainSubstring("ratings-v1"), Not(ContainSubstring(PreparedImageV1)))

// but also check if prod is intact
EnsureProdRouteIsReachable(namespace, ContainSubstring("ratings-v1"), Not(ContainSubstring(PreparedImageV1)))
})
})
})
})
})

// EnsureAllPodsAreReady make sure all Pods are in Ready state in given namespace.
func EnsureAllPodsAreReady(namespace string) {
Eventually(AllPodsReady(namespace), 5*time.Minute, 5*time.Second).Should(BeTrue())
}

// EnsureAllDeploymentPodsAreReady make sure all Pods are in Ready state in given namespace.
func EnsureAllDeploymentPodsAreReady(namespace string) {
Eventually(AllDeploymentsAndPodsReady(namespace), 5*time.Minute, 5*time.Second).Should(BeTrue())
Expand Down Expand Up @@ -356,6 +399,7 @@ func Stop(ike *cmd.Cmd) {
Eventually(ike.Done(), 1*time.Minute).Should(BeClosed())
}

// DumpEnvironmentDebugInfo prints tons of noise about the cluster state when test fails.
func DumpEnvironmentDebugInfo(namespace, dir string) {
pods := GetAllPods(namespace)
for _, pod := range pods {
Expand Down
14 changes: 11 additions & 3 deletions integration/tekton/tasks/ike-create/ike-create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
annotations:
tekton.dev/displayName: Ike Create
tekton.dev/tags: istio, telepresence
tekton.dev/pipelines.minVersion: 0.21.0
tekton.dev/pipelines.minVersion: 0.16.0
spec:
description: >-
`ike-create` creates a new `session` object for `istio-workspace` and will
Expand All @@ -26,6 +26,7 @@ spec:
- name: route
type: string
description: How to route
default: ""
- name: image
type: string
description: The image to use for the route
Expand All @@ -36,5 +37,12 @@ spec:
- name: ike
image: released-image
script: |
STATE=`ike create --session $(params.session) --route $(params.route) --deployment $(params.target) --namespace $(params.namespace) --image $(params.image) --json`
echo "$STATE" | grep \"hosts\": | cut -d \" -f 4 > /tekton/results/url
test ! -z "$(params.route)" && export ROUTE="--route $(params.route)"
STATE=`ike create --session $(params.session) $ROUTE --deployment $(params.target) --namespace $(params.namespace) --image $(params.image) --json`
if [[ $? -ne 0 ]]; then
error=$?
echo $STATE
exit $error
fi
echo "$STATE" | grep \"hosts\": | cut -d \" -f 4 | tr -d '\n' > /tekton/results/url
34 changes: 17 additions & 17 deletions integration/tekton/tasks/ike-create/samples/ike-create.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: preview-customer
taskRef:
name: ike-create
kind: Task
runAfter:
- image-customer
params:
- name: session
value: $(params.git-pr-head-ref)
- name: target
value: customer-v1
- name: route
value: "header:ike-session-id=$(params.git-pr-head-ref)"
- name: namespace
value: workspace-demo
- name: image
value: image-registry.openshift-image-registry.svc:5000/workspace-demo/$(params.git-repo-name)-customer:$(params.git-revision)
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
name: ike-create-run
spec:
serviceAccountName: istio-workspace
taskRef:
name: ike-create
params:
- name: target
value: ratings-v1
- name: session
value: $(params.git-pr-head-ref)
- name: image
value: quay.io/workspace-demo/$(params.git-repo-name)-ratings:$(params.git-revision)
- name: route
value: "header:ike-session-id=$(params.git-pr-head-ref)"

This file was deleted.

Loading

0 comments on commit b365862

Please sign in to comment.