From 19c52bc402f312d0bf3fb62cb1bda365caf9349e Mon Sep 17 00:00:00 2001 From: aattuluri <44482891+aattuluri@users.noreply.github.com> Date: Mon, 23 Sep 2019 15:00:15 -0700 Subject: [PATCH] Fix running tests (#14) * Fix running tests. Refactor. --- CONTRIBUTING.md | 96 ++------------------- Makefile | 2 +- README.md | 4 +- examples/client.yaml | 59 ------------- examples/dependency_record.yaml | 10 --- examples/mc-namespace.yaml | 8 -- examples/serverv1.0.yaml | 40 --------- {test => install}/scripts/cluster-secret.sh | 0 {test => install}/scripts/redirect-dns.sh | 0 test/data/depedency1.yaml | 23 ----- test/data/globalTraffic-env.yaml | 55 ------------ test/data/globalTraffic1.yaml | 38 -------- 12 files changed, 12 insertions(+), 323 deletions(-) delete mode 100644 examples/client.yaml delete mode 100644 examples/dependency_record.yaml delete mode 100644 examples/mc-namespace.yaml delete mode 100644 examples/serverv1.0.yaml rename {test => install}/scripts/cluster-secret.sh (100%) rename {test => install}/scripts/redirect-dns.sh (100%) delete mode 100644 test/data/depedency1.yaml delete mode 100644 test/data/globalTraffic-env.yaml delete mode 100644 test/data/globalTraffic1.yaml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 281dd16e..c3a4a336 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,91 +1,13 @@ # Contributing to Admiral -## Pre-requisite -1. We'll need at least 2 kubernetes clusters running istio to see the power of Admiral :). -2. The ingressgateway loadbalancer is accessible from each cluster -3. The admiral repository is cloned: ```git clone https://github.com/istio-ecosystem/admiral.git``` -4. GoLand has been downloaded ([download it here](https://www.jetbrains.com/go/download/download-thanks.html?platform=mac)) -## Setting up Admiral for development -1. Decide the cluster admiral will run on. This is will be referred to as the `local cluster`. The `local cluster` is where we will deploy the client. - Set the env variable `LOCAL_CLUSTER` to point to the local cluster's KUBECONFIG. +We welcome contributions :) - ```export LOCAL_CLUSTER=/admins@your-local.cluster.k8s.local``` -2. Our other cluster will be referred to as the`remote cluster`. The `remote cluster` is where we will deploy a remote service that gets accessed by the client running in the `local cluster`, using an admiral generated service name. - Set the env variable `REMOTE_CLUSTER` to point to the remote cluster KUBECONFIG. - - ```export REMOTE_CLUSTER=/admins@you-remote.cluster.k8s.local``` +## Submitting PRs +* Make sure to check existing issues and file an issue before starting to work on a feature/bug. This will help prevent duplication of work. -3. Set up namespaces needed for the `remote cluster` and `local cluster`: - ``` - export KUBECONFIG=$REMOTE_CLUSTER - kubectl apply -f install/admiral/admiral-sync-ns.yaml - - export KUBECONFIG=$LOCAL_CLUSTER - kubectl apply -f install/admiral/admiral-sync-ns.yaml - ``` - `Note:` You can also override these namespaces when you start admiral -4. Provision a service account on `local cluster` and `remote cluster`. Admiral will use it to talk to the k8s api server between clusters. - ``` - export KUBECONFIG=$REMOTE_CLUSTER - kubectl apply -f install/admiral/remote-sa.yaml - - export KUBECONFIG=$LOCAL_CLUSTER - kubectl apply -f install/admiral/remote-sa.yaml - ``` -5. Run the following shell scripts (this fetches service account's secret from a cluster and drops it into `admiral-secret-ns` namespace in local cluster): - ``` - sh test/scripts/cluster-secret.sh $LOCAL_CLUSTER $REMOTE_CLUSTER - sh test/scripts/cluster-secret.sh $LOCAL_CLUSTER $LOCAL_CLUSTER - ``` -6. Create dependencies and global traffic policies CRDs in local cluster and create global traffic policy in remote cluser - ``` - export KUBECONFIG=$LOCAL_CLUSTER - kubectl apply -f admiral/crd/dependency.yaml - kubectl apply -f admiral/crd/globalTraffic.yaml - - export KUBECONFIG=$REMOTE_CLUSTER - kubectl apply -f admiral/crd/globalTraffic.yaml - ``` -7. Open the admiral project in GoLand - * navigate to the `Run` tab and click `Edit Configurations` - * in the field `Program arguments` add the following parameters: - - ``` - --kube_config - ``` - * check run after build - * specify `-i` in go `Go tool arguments` - -8. Run admiral/admiral/cmd/admiral/cmd/main.go to make sure admiral started successfully -9. Create namespace in both clusters - ``` - export KUBECONFIG=$REMOTE_CLUSTER - kubectl apply -f examples/mc-namespace.yaml - - export KUBECONFIG=$LOCAL_CLUSTER - kubectl apply -f examples/mc-namespace.yaml - ``` -10. Update examples/serverv1.0.yaml with the correct role, policy id, and identity. Deploy serverv1 on remote cluster - ``` - export KUBECONFIG=$REMOTE_CLUSTER - kubectl apply -f examples/serverv1.0.yaml -n mc - ``` -11. Update examples/client.yaml with the correct role, policy id, and assetId. Deploy client on local cluster - ``` - export KUBECONFIG=$LOCAL_CLUSTER - kubectl apply -f examples/client.yaml -n mc - ``` -12. Create dependency record in the `local cluster` - ``` - export KUBECONFIG=$LOCAL_CLUSTER - kubectl apply -f examples/dependency_record.yaml - ``` - -13. At this point, the client app can discover names for server by filtering Istio Service Entries with identity label. - Shell into client to verify call to server is successful - ``` - export KUBECONFIG=$LOCAL_CLUSTER - kubectl exec -ti -c client sh -n mc - - curl -v stage.server.global/hello - ``` +## Setting up for local Development +* Use `Single Cluster` or `Multi-Cluster` sections [HERE](./README.MD) to set up the local test cluster. +* Run `admiral` from your IDE. +``` +/admiral/cmd/admiral/main.go --kube_config +``` \ No newline at end of file diff --git a/Makefile b/Makefile index c4c83020..1f3c84f0 100644 --- a/Makefile +++ b/Makefile @@ -41,7 +41,7 @@ build-mac: $(GOBUILD) -o $(BINARY_DARWIN) -v $(MAIN_PATH_ADMIRAL) test: - $(GOTEST) ./... + $(GOTEST) -v `go list ./... | grep -v github.com/admiral/admiral/pkg/client` clean: $(GOCLEAN) diff --git a/README.md b/README.md index 82ca54e4..458ad437 100644 --- a/README.md +++ b/README.md @@ -80,11 +80,11 @@ kubectl apply -f ./out/yaml/demosinglecluster.yaml ``` #create the secret for admiral to monitor. #Since this is for a single cluster demo the remote and local context are the same -./test/scripts/cluster-secret.sh $KUBECONFIG $KUBECONFIG admiral +./install/scripts/cluster-secret.sh $KUBECONFIG $KUBECONFIG admiral ``` ``` #point hosts ending in global to be resolved by istio coredns -./test/scripts/redirect-dns.sh +./install/scripts/redirect-dns.sh ``` #### Setup Sample Apps diff --git a/examples/client.yaml b/examples/client.yaml deleted file mode 100644 index ebcc8eed..00000000 --- a/examples/client.yaml +++ /dev/null @@ -1,59 +0,0 @@ -# Copyright 2017 Istio Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -################################################################################################## -# Sleep service -################################################################################################## -apiVersion: v1 -kind: ServiceAccount -metadata: - name: client ---- -apiVersion: v1 -kind: Service -metadata: - name: client - labels: - app: client - identity: Admiral.platform.mesh.client - env: stage -spec: - ports: - - port: 80 - name: http - selector: - app: client ---- -apiVersion: extensions/v1beta1 -kind: Deployment -metadata: - name: client -spec: - replicas: 1 - template: - metadata: - labels: - app: client - identity: Admiral.platform.mesh.client - env: stage - annotations: - sidecar.istio.io/inject: "true" - spec: - serviceAccountName: client - containers: - - name: client - image: pstauffer/curl - command: ["/bin/sleep", "3650d"] - imagePullPolicy: IfNotPresent ---- diff --git a/examples/dependency_record.yaml b/examples/dependency_record.yaml deleted file mode 100644 index 6d839972..00000000 --- a/examples/dependency_record.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: admiral.io/v1alpha1 -kind: Dependency -metadata: - name: dependency-v2 - namespace: admiral -spec: - source: Admiral.platform.mesh.client - identityLabel: identity - destinations: - - Admiral.platform.mesh.server diff --git a/examples/mc-namespace.yaml b/examples/mc-namespace.yaml deleted file mode 100644 index e4e32c98..00000000 --- a/examples/mc-namespace.yaml +++ /dev/null @@ -1,8 +0,0 @@ ---- -apiVersion: v1 -kind: Namespace -metadata: - name: mc - labels: - istio-injection: enabled ---- diff --git a/examples/serverv1.0.yaml b/examples/serverv1.0.yaml deleted file mode 100644 index 9091d3bd..00000000 --- a/examples/serverv1.0.yaml +++ /dev/null @@ -1,40 +0,0 @@ ---- -apiVersion: v1 -kind: Service -metadata: - name: server - labels: - app: server - identity: Admiral.platform.mesh.server - env: stage -spec: - ports: - - port: 80 - targetPort: 5000 - name: http - selector: - app: server ---- -apiVersion: extensions/v1beta1 -kind: Deployment -metadata: - name: server-v1 -spec: - replicas: 1 - template: - metadata: - labels: - app: server - identity: Admiral.platform.mesh.server - version: v1 - env: stage - annotations: - sidecar.istio.io/inject: "true" - spec: - containers: - - name: server - image: istio/examples-helloworld-v1 - imagePullPolicy: IfNotPresent - ports: - - containerPort: 5000 ---- diff --git a/test/scripts/cluster-secret.sh b/install/scripts/cluster-secret.sh similarity index 100% rename from test/scripts/cluster-secret.sh rename to install/scripts/cluster-secret.sh diff --git a/test/scripts/redirect-dns.sh b/install/scripts/redirect-dns.sh similarity index 100% rename from test/scripts/redirect-dns.sh rename to install/scripts/redirect-dns.sh diff --git a/test/data/depedency1.yaml b/test/data/depedency1.yaml deleted file mode 100644 index 04bc8b77..00000000 --- a/test/data/depedency1.yaml +++ /dev/null @@ -1,23 +0,0 @@ ---- -apiVersion: admiral.io/v1aplha1 -kind: Dependency -metadata: - name: dep1 -spec: - source: "identity3" - identityLabel: identity - destinations: - - "identity1" - - "identity2" - ---- -apiVersion: admiral.io/v1aplha1 -kind: Dependency -metadata: - name: dep2 -spec: - source: "identity1" - identityLabel: identity - destinations: - - "identity2" - - "identity3" \ No newline at end of file diff --git a/test/data/globalTraffic-env.yaml b/test/data/globalTraffic-env.yaml deleted file mode 100644 index fc37ef96..00000000 --- a/test/data/globalTraffic-env.yaml +++ /dev/null @@ -1,55 +0,0 @@ - - ---- -apiVersion: admiral.io/v1alpha1 -kind: GlobalTrafficPolicy -metadata: - name: policy-identity1-prd -spec: - selector: - identity: identity1 - env: prd - policy: - - dns: prd.service1 - lbtype: TOPOLOGY - - dns: prd.service1.us-west-2 - lbtype: FAILOVER - target: - - region: us-west-2 - weight: 100 - - region: us-east-2 - weight: 0 - - dns: prd.service1.us-east-2 - lbtype: FAILOVER - target: - - region: us-west-2 - weight: 0 - - region: us-east-2 - weight: 100 ---- -apiVersion: admiral.io/v1alpha1 -kind: GlobalTrafficPolicy -metadata: - name: policy-identity1-stage -spec: - selector: - identity: identity1 - env: stage - policy: - - dns: stage.service2 - lbtype: TOPOLOGY - - dns: stage.service2-west2 - lbtype: FAILOVER - target: - - region: us-west-2 - weight: 100 - - region: us-east-2 - weight: 0 - - dns: stage.service2-east2 - lbtype: FAILOVER - target: - - region: us-west-2 - weight: 0 - - region: us-east-2 - weight: 100 ---- \ No newline at end of file diff --git a/test/data/globalTraffic1.yaml b/test/data/globalTraffic1.yaml deleted file mode 100644 index 48b62030..00000000 --- a/test/data/globalTraffic1.yaml +++ /dev/null @@ -1,38 +0,0 @@ ---- -apiVersion: admiral.io/v1alpha1 -kind: GlobalTrafficPolicy -metadata: - name: policy-identity1 -spec: - selector: - identity: identity1 - policy: - - dns: stage.service1.global - lbtype: TOPOLOGY - ---- -apiVersion: admiral.io/v1alpha1 -kind: GlobalTrafficPolicy -metadata: - name: policy-identity2 -spec: - selector: - identity: identity2 - policy: - - dns: stage.service2 - lbtype: TOPOLOGY - - dns: stage.service2.uswest2 - lbtype: FAILOVER - target: - - region: us-west-2 - weight: 100 - - region: us-east-2 - weight: 0 - - dns: stage.service2-east - lbtype: FAILOVER - target: - - region: us-west-2 - weight: 0 - - region: us-east-2 - weight: 100 ---- \ No newline at end of file