Skip to content

Commit 020e098

Browse files
authored
Set AWS_REGION (#63)
1 parent 761c74a commit 020e098

File tree

13 files changed

+129
-46
lines changed

13 files changed

+129
-46
lines changed

CONTRIBUTING.md

Lines changed: 91 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# Contributing Guidelines
22

3+
* [Getting Started](#getting-started)
4+
+ [Local Setup](#local-setup)
5+
- [Prerequisites](#prerequisites)
6+
- [Cluster Setup](#cluster-setup)
7+
- [Run the controller from outside the cluster](#run-the-controller-from-outside-the-cluster)
8+
- [Build and deploy to the cluster](#build-and-deploy-to-the-cluster)
9+
- [Run unit tests](#run-unit-tests)
10+
- [Cleanup](#cleanup)
11+
+ [Deploying to a cluster](#deploying-to-a-cluster)
12+
+ [Build and push docker image to ECR](#build-and-push-docker-image-to-ecr)
13+
- [Deployment](#deployment)
14+
- [Uninstallation](#uninstallation)
15+
* [Reporting Bugs/Feature Requests](#reporting-bugsfeature-requests)
16+
* [Contributing via Pull Requests](#contributing-via-pull-requests)
17+
* [Finding contributions to work on](#finding-contributions-to-work-on)
18+
* [Code of Conduct](#code-of-conduct)
19+
* [Security issue notifications](#security-issue-notifications)
20+
* [Licensing](#licensing)
21+
322
Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
423
documentation, we greatly value feedback and contributions from our community.
524

@@ -8,38 +27,50 @@ information to effectively respond to your bug report or contribution.
827

928
## Getting Started
1029

11-
### Build and Run locally
30+
### Local Setup
1231

1332
#### Prerequisites
1433

1534
In order to build and run locally:
1635

1736
* Make sure to have `kubectl` [installed](https://kubernetes.io/docs/tasks/tools/install-kubectl/), at least version `1.15` or above.
1837
* Make sure to have `kind` [installed](https://kind.sigs.k8s.io/docs/user/quick-start/#installation).
19-
* Make sure, you have created a [HttpNamespace](https://docs.aws.amazon.com/cloud-map/latest/api/API_CreateHttpNamespace.html) in AWS Cloud Map. The examples below assumes the namespace name to be `demo`
38+
* Make sure, you have access to AWS Cloud Map. As per exercise below, AWS Cloud Map namespace `example` of the type [HttpNamespace](https://docs.aws.amazon.com/cloud-map/latest/api/API_CreateHttpNamespace.html) will be automatically created.
2039

2140
Note that this walk-through assumes throughout to operate in the `us-west-2` region.
2241

2342
```sh
2443
export AWS_REGION=us-west-2
2544
```
2645

27-
#### Cluster provisioning
46+
#### Cluster Setup
2847

2948
Spin up a local Kubernetes cluster using `kind`
49+
3050
```sh
3151
kind create cluster --name my-cluster
3252
# Creating cluster "my-cluster" ...
3353
# ...
3454
```
3555

3656
When completed, set the kubectl context
57+
3758
```sh
3859
kind export kubeconfig --name my-cluster
3960
# Set kubectl context to "kind-my-cluster"
4061
```
4162

63+
Create `example` namespace in the cluster
64+
65+
```sh
66+
kubectl create namespace example
67+
# namespace/example created
68+
```
69+
70+
#### Run the controller from outside the cluster
71+
4272
To register the custom CRDs (`ServiceImport`, `ServiceExport`) in the cluster and create installers
73+
4374
```sh
4475
make install
4576
# ...
@@ -48,48 +79,88 @@ make install
4879
```
4980

5081
To run the controller, run the following command. The controller runs in an infinite loop so open another terminal to create CRDs.
82+
5183
```sh
5284
make run
5385
```
5486

55-
Create `demo` namespace
56-
```sh
57-
kubectl create namespace demo
58-
# namespace/demo created
59-
```
87+
Apply deployment, service and serviceexport configs
6088

61-
Apply deployment, service and export configs
6289
```sh
63-
kubectl apply -f samples/demo-deployment.yaml
90+
kubectl apply -f samples/example-deployment.yaml
6491
# deployment.apps/nginx-deployment created
65-
kubectl apply -f samples/demo-service.yaml
66-
# service/demo-service created
67-
kubectl apply -f samples/demo-export.yaml
68-
# serviceexport.multicluster.x-k8s.io/demo-service created
92+
kubectl apply -f samples/example-service.yaml
93+
# service/my-service created
94+
kubectl apply -f samples/example-serviceexport.yaml
95+
# serviceexport.multicluster.x-k8s.io/my-service created
6996
```
7097

7198
Check running controller if it correctly detects newly created resources
99+
100+
```
101+
controllers.ServiceExport updating Cloud Map service {"serviceexport": "example/my-service", "namespace": "example", "name": "my-service"}
102+
cloudmap fetching a service {"namespaceName": "example", "serviceName": "my-service"}
103+
cloudmap creating a new service {"namespace": "example", "name": "my-service"}
104+
```
105+
106+
#### Build and deploy to the cluster
107+
108+
Build a `controller:local` (`--no-cache` args can be set to update the existing docker image)
109+
110+
```shell
111+
make docker-build IMG=controller:local ARGS="--no-cache"
112+
# ...
113+
# docker build --no-cache -t controller:local .
114+
# ...
115+
#
116+
```
117+
118+
Load the controller docker image into the kind cluster `my-cluster`
119+
```shell
120+
kind load docker-image controller:local --name my-cluster
121+
# Image: "controller:local" with ID "sha256:xxx" not yet present on node "my-cluster-control-plane", loading...
122+
```
123+
124+
> **The controller still needs credentials to interact to AWS SDK.** We are not supporting this configuration out of box. There are multiple ways to achieve this within the cluster.
125+
126+
Finally, create the controller resources in the cluster.
127+
```shell
128+
make deploy IMG=controller:local AWS_REGION=us-west-2
129+
# customresourcedefinition.apiextensions.k8s.io/serviceexports.multicluster.x-k8s.io configured
130+
# customresourcedefinition.apiextensions.k8s.io/serviceimports.multicluster.x-k8s.io created
131+
# ...
132+
# deployment.apps/cloud-map-mcs-controller-manager created
72133
```
73-
controllers.ServiceExport updating Cloud Map service {"serviceexport": "demo/demo-service", "namespace": "demo", "name": "demo-service"}
74-
cloudmap fetching a service {"namespaceName": "demo", "serviceName": "demo-service"}
75-
cloudmap creating a new service {"namespace": "demo", "name": "demo-service"}
134+
135+
Stream the controller logs
136+
```shell
137+
kubectl logs -f -l control-plane=controller-manager -c manager -n cloud-map-mcs-system
76138
```
77139

78140
#### Run unit tests
79141

80142
Use command below to run the unit test
143+
81144
```sh
82145
make test
83146
```
84147

85148
#### Cleanup
86149

87150
Use the command below to clean all the generated files
151+
88152
```sh
89153
make clean
90154
```
91155

156+
Use the command below to remove the CRDs from the cluster
157+
158+
```sh
159+
make uninstall
160+
```
161+
92162
Use the command below to delete the cluster `my-cluster`
163+
93164
```sh
94165
kind delete cluster --name my-cluster
95166
```
@@ -108,23 +179,17 @@ make docker-build docker-push IMG=<YOUR ACCOUNT ID>.dkr.ecr.<ECR REGION>.amazona
108179

109180
#### Deployment
110181

111-
You must specify AWS access credentials for the operator. You can do so via environment variables, or by creating them.
182+
You must setup the AWS access credentials. Also, set the AWS_REGION environment variable like `export AWS_REGION=us-west-2`
112183

113-
Any one of below three options will work:
114184
```sh
115185
# With an IAM user.
116186
make deploy
117-
118-
# Use an existing access key
119-
OPERATOR_AWS_ACCESS_KEY_ID=xxx OPERATOR_AWS_SECRET_KEY=yyy make deploy
120-
121-
# Use an AWS profile
122-
OPERATOR_AWS_PROFILE=default make deploy
123187
```
124188

125189
#### Uninstallation
126190

127-
To remove the operator from your cluster, run
191+
To remove the controller from your cluster, run
192+
128193
```sh
129194
make undeploy
130195
```

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ PKG:=github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/version
66
IMG ?= controller:latest
77
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
88
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
9+
# AWS Region
10+
AWS_REGION ?= us-east-1
911

1012
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
1113
ifeq (,$(shell go env GOBIN))
@@ -67,10 +69,10 @@ run: manifests generate generate-mocks fmt vet ## Run a controller from your hos
6769
go run ./main.go
6870

6971
docker-build: test ## Build docker image with the manager.
70-
docker build -t ${IMG} .
72+
docker build $(ARGS) -t ${IMG} .
7173

7274
docker-push: ## Push docker image with the manager.
73-
docker push ${IMG}
75+
docker push $(ARGS) ${IMG}
7476

7577
clean:
7678
rm -rf $(MOCKS_DESTINATION) bin/ testbin/ cover.out
@@ -85,7 +87,7 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified
8587

8688
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
8789
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
88-
$(KUSTOMIZE) build config/default | kubectl apply -f -
90+
AWS_REGION=${AWS_REGION} $(KUSTOMIZE) build config/default | kubectl apply -f -
8991

9092
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
9193
$(KUSTOMIZE) build config/default | kubectl delete -f -

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ AWS Cloud Map multi-cluster service discovery for Kubernetes (K8s) is a controll
2121

2222
First, install the controller with latest release on at least 2 AWS EKS clusters. Nodes must have sufficient IAM permissions to perform CloudMap operations.
2323

24+
> **_NOTE:_** AWS region environment variable should be set like `export AWS_REGION=us-west-2`
25+
2426
```sh
2527
kubectl apply -k "github.com/aws/aws-cloud-map-mcs-controller-for-k8s/config/controller_install_release"
2628
```
@@ -51,9 +53,9 @@ metadata:
5153
*See the `samples` directory for a set of example yaml files to set up a service and export it. To apply the sample files run*
5254
```sh
5355
kubectl create namespace demo
54-
kubectl apply -f https://raw.githubusercontent.com/aws/aws-cloud-map-mcs-controller-for-k8s/main/samples/demo-deployment.yaml
55-
kubectl apply -f https://raw.githubusercontent.com/aws/aws-cloud-map-mcs-controller-for-k8s/main/samples/demo-service.yaml
56-
kubectl apply -f https://raw.githubusercontent.com/aws/aws-cloud-map-mcs-controller-for-k8s/main/samples/demo-export.yaml
56+
kubectl apply -f https://raw.githubusercontent.com/aws/aws-cloud-map-mcs-controller-for-k8s/main/samples/example-deployment.yaml
57+
kubectl apply -f https://raw.githubusercontent.com/aws/aws-cloud-map-mcs-controller-for-k8s/main/samples/example-service.yaml
58+
kubectl apply -f https://raw.githubusercontent.com/aws/aws-cloud-map-mcs-controller-for-k8s/main/samples/example-serviceexport.yaml
5759
```
5860

5961
### Import services
@@ -67,6 +69,8 @@ kubectl get ServiceImport -A
6769

6870
AWS Cloud Map MCS Controller for K8s adheres to the [SemVer](https://semver.org/) specification. Each release updates the major version tag (eg. `vX`), a major/minor version tag (eg. `vX.Y`) and a major/minor/patch version tag (eg. `vX.Y.Z`). To see a full list of all releases, refer to our [Github releases page](https://github.com/aws/aws-cloud-map-mcs-controller-for-k8s/releases).
6971

72+
> **_NOTE:_** AWS region environment variable should be set like `export AWS_REGION=us-west-2`
73+
7074
To install from a release run
7175
```sh
7276
kubectl apply -k "github.com/aws/aws-cloud-map-mcs-controller-for-k8s/config/controller_install_release[?ref=*git version tag*]"

config/controller_install_latest/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
bases:
1+
resources:
22
- ../default
33

44
images:

config/controller_install_release/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
bases:
1+
resources:
22
- ../default
33

44
images:

config/default/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namePrefix: cloud-map-mcs-
1212
#commonLabels:
1313
# someName: someValue
1414

15-
bases:
15+
resources:
1616
- ../crd
1717
- ../rbac
1818
- ../manager

config/manager/aws.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AWS_REGION

config/manager/kustomization.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ configMapGenerator:
88
- files:
99
- controller_manager_config.yaml
1010
name: manager-config
11-
apiVersion: kustomize.config.k8s.io/v1beta1
12-
kind: Kustomization
11+
- envs:
12+
- aws.properties
13+
name: aws-config
14+
1315
images:
1416
- name: controller
1517
newName: controller

config/manager/manager.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,11 @@ spec:
5252
requests:
5353
cpu: 100m
5454
memory: 20Mi
55+
env:
56+
- name: AWS_REGION
57+
valueFrom:
58+
configMapKeyRef:
59+
name: aws-config
60+
key: AWS_REGION
5561
serviceAccountName: controller-manager
5662
terminationGracePeriodSeconds: 10

main.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,27 +86,30 @@ func main() {
8686
}
8787

8888
// TODO: configure session
89+
awsRegion := os.Getenv("AWS_REGION")
90+
setupLog.Info("configuring AWS session", "AWS_REGION", awsRegion)
8991
awsCfg, err := config.LoadDefaultConfig(context.TODO(),
90-
config.WithRegion(os.Getenv("AWS_REGION")),
92+
config.WithRegion(awsRegion),
9193
)
9294
if err != nil {
93-
setupLog.Error(err, "unable to configure AWS session")
95+
setupLog.Error(err, "unable to configure AWS session", "AWS_REGION", awsRegion)
9496
os.Exit(1)
9597
}
9698

99+
serviceDiscoveryClient := cloudmap.NewServiceDiscoveryClient(&awsCfg)
97100
if err = (&controllers.ServiceExportReconciler{
98101
Client: mgr.GetClient(),
99102
Log: ctrl.Log.WithName("controllers").WithName("ServiceExport"),
100103
Scheme: mgr.GetScheme(),
101-
Cloudmap: cloudmap.NewServiceDiscoveryClient(&awsCfg),
104+
Cloudmap: serviceDiscoveryClient,
102105
}).SetupWithManager(mgr); err != nil {
103106
setupLog.Error(err, "unable to create controller", "controller", "ServiceExport")
104107
os.Exit(1)
105108
}
106109

107110
cloudMapReconciler := &controllers.CloudMapReconciler{
108111
Client: mgr.GetClient(),
109-
Cloudmap: cloudmap.NewServiceDiscoveryClient(&awsCfg),
112+
Cloudmap: serviceDiscoveryClient,
110113
Logger: ctrl.Log.WithName("controllers").WithName("CloudMap"),
111114
}
112115

0 commit comments

Comments
 (0)