Skip to content

Commit cff581f

Browse files
authored
Add support for Ready, Hostname and Nodename Endpoint attributes. And some other refactoring changes. (#210)
* Add support for Ready, Hostname and Nodename Endpoint attributes. And some other refactoring changes. Changes: * Add support for Ready, Hostname and Nodename Endpoint attributes. * Refactor cluster properties changes - move to model package, simplify code. * Add controller watches for Service event. Filter out events if cluster properties is not defined. * Improve kind integration test - add curl test, use dnsutils pod for dig, use ngnix app for deployment * Fix build command test * Update the Leader resource name
1 parent e3d4dc4 commit cff581f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+943
-749
lines changed

CONTRIBUTING.md

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
# Contributing Guidelines
22

3-
* [Architecture Overview](#architecture-overview)
4-
* [Getting Started](#getting-started)
5-
+ [Local Setup](#local-setup)
6-
- [Prerequisites](#prerequisites)
7-
- [Cluster Setup](#cluster-setup)
8-
- [Run the controller from outside the cluster](#run-the-controller-from-outside-the-cluster)
9-
- [Build and deploy to the cluster](#build-and-deploy-to-the-cluster)
10-
- [Run unit tests](#run-unit-tests)
11-
- [Cleanup](#cleanup)
12-
+ [Deploying to a cluster](#deploying-to-a-cluster)
13-
* [Integration testing](#integration-testing)
14-
* [Build and push docker image to ECR](#build-and-push-docker-image-to-ecr)
15-
* [Reporting Bugs/Feature Requests](#reporting-bugs-feature-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-
223
Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional
234
documentation, we greatly value feedback and contributions from our community.
245

256
Please read through this document before submitting any issues or pull requests to ensure we have all the necessary
267
information to effectively respond to your bug report or contribution.
278

9+
<!-- TOC -->
10+
* [Contributing Guidelines](#contributing-guidelines)
11+
* [Architecture Overview](#architecture-overview)
12+
* [Getting Started](#getting-started)
13+
* [Build and Unit Tests](#build-and-unit-tests)
14+
* [Local Setup](#local-setup)
15+
* [Prerequisites](#prerequisites)
16+
* [Kind Cluster Setup](#kind-cluster-setup)
17+
* [Run the controller from outside the cluster](#run-the-controller-from-outside-the-cluster)
18+
* [Build and deploy controller into the cluster](#build-and-deploy-controller-into-the-cluster)
19+
* [Local integration testing](#local-integration-testing)
20+
* [Build and push docker image](#build-and-push-docker-image)
21+
* [Reporting Bugs/Feature Requests](#reporting-bugsfeature-requests)
22+
* [Contributing via Pull Requests](#contributing-via-pull-requests)
23+
* [Finding contributions to work on](#finding-contributions-to-work-on)
24+
* [Code of Conduct](#code-of-conduct)
25+
* [Security issue notifications](#security-issue-notifications)
26+
* [Licensing](#licensing)
27+
<!-- TOC -->
28+
2829
## Architecture Overview
2930

3031
![Architecture diagram](docs/architecture-overview.png?raw=true)
@@ -34,6 +35,23 @@ information to effectively respond to your bug report or contribution.
3435

3536
## Getting Started
3637

38+
### Build and Unit Tests
39+
40+
Use command below to run the unit test:
41+
```sh
42+
make test
43+
```
44+
45+
Use command below to build:
46+
```sh
47+
make build
48+
```
49+
50+
Use the command below to perform cleanup:
51+
```sh
52+
make clean
53+
```
54+
3755
### Local Setup
3856

3957
#### Prerequisites
@@ -50,7 +68,7 @@ Note that this walk-through assumes throughout to operate in the `us-west-2` reg
5068
export AWS_REGION=us-west-2
5169
```
5270

53-
#### Cluster Setup
71+
#### Kind Cluster Setup
5472

5573
Spin up a local Kubernetes cluster using `kind`:
5674

@@ -92,7 +110,7 @@ kubectl apply -f samples/example-clusterproperty.yaml
92110
> **Note:** If you are creating multiple clusters, ensure you create unique `id.k8s.io` identifiers for each cluster.
93111
94112

95-
To run the controller, run the following command. The controller runs in an infinite loop so open another terminal to create CRDs.
113+
To run the controller, run the following command. The controller runs in an infinite loop so open another terminal to create CRDs. (Ctrl+C to exit)
96114
```sh
97115
make run
98116
```
@@ -114,7 +132,12 @@ cloudmap fetching a service {"namespaceName": "example", "servic
114132
cloudmap creating a new service {"namespace": "example", "name": "my-service"}
115133
```
116134

117-
#### Build and deploy to the cluster
135+
Use the command below to remove the CRDs from the cluster:
136+
```sh
137+
make uninstall
138+
```
139+
140+
#### Build and deploy controller into the cluster
118141

119142
Build local `controller` docker image:
120143
```sh
@@ -136,7 +159,8 @@ kind load docker-image controller:local --name my-cluster
136159
Finally, create the controller resources in the cluster:
137160
```sh
138161
make deploy IMG=controller:local AWS_REGION=us-west-2
139-
# customresourcedefinition.apiextensions.k8s.io/serviceexports.multicluster.x-k8s.io configured
162+
# customresourcedefinition.apiextensions.k8s.io/clusterproperties.about.k8s.io created
163+
# customresourcedefinition.apiextensions.k8s.io/serviceexports.multicluster.x-k8s.io created
140164
# customresourcedefinition.apiextensions.k8s.io/serviceimports.multicluster.x-k8s.io created
141165
# ...
142166
# deployment.apps/cloud-map-mcs-controller-manager created
@@ -152,38 +176,13 @@ To remove the controller from your cluster, run:
152176
make undeploy
153177
```
154178

155-
#### Run unit tests
156-
157-
Use command below to run the unit test:
158-
```sh
159-
make test
160-
```
161-
162-
#### Cleanup
163-
164-
Use the command below to perform cleanup:
165-
```sh
166-
make clean
167-
```
168-
169-
Use the command below to remove the CRDs from the cluster:
170-
```sh
171-
make uninstall
172-
```
173-
174179
Use the command below to delete the cluster `my-cluster`:
175180
```sh
176181
kind delete cluster --name my-cluster
177182
```
178183

179-
### Deploying to a cluster
180-
181-
You must first push a Docker image containing the changes to a Docker repository like ECR, Github packages, or DockerHub. The repo is configured to use Github Actions to automatically publish the docker image upon push to `main` branch. The image URI will be `ghcr.io/[Your forked repo name here]` You can enable this for forked repos by enabling Github actions on your forked repo in the "Actions" tab of forked repo.
182-
183-
If you are deploying to cluster using kustomize templates from the `config` directory, you will need to override the image URI away from `ghcr.io/aws/aws-cloud-map-mcs-controller-for-k8s` in order to use your own docker images.
184-
184+
### Local integration testing
185185

186-
## Local integration testing
187186
The end-to-end integration test suite can be run locally to validate controller core functionality. This will provision a local Kind cluster and build and run the AWS Cloud Map MCS Controller for K8s. The test will verify service endpoints sync with AWS Cloud Map. If successful, the suite will then de-provision the local test cluster and delete AWS Cloud Map namespace `aws-cloud-map-mcs-e2e` along with test service and service instance resources:
188187
```sh
189188
make kind-integration-suite
@@ -194,10 +193,15 @@ If integration test suite fails for some reason, you can perform a cleanup:
194193
make kind-integration-cleanup
195194
```
196195

197-
## Build and push docker image to ECR
196+
## Build and push docker image
197+
198+
You must first push a Docker image containing the changes to a Docker repository like ECR, Github packages, or DockerHub. The repo is configured to use Github Actions to automatically publish the docker image upon push to `main` branch. The image URI will be `ghcr.io/[Your forked repo name here]` You can enable this for forked repos by enabling Github actions on your forked repo in the "Actions" tab of forked repo.
199+
200+
If you are deploying to cluster using kustomize templates from the `config` directory, you will need to override the image URI away from `ghcr.io/aws/aws-cloud-map-mcs-controller-for-k8s` in order to use your own docker images.
198201

202+
To push the docker image into personal repo:
199203
```sh
200-
make docker-build docker-push IMG=<YOUR ACCOUNT ID>.dkr.ecr.<ECR REGION>.amazonaws.com/<ECR REPOSITORY>
204+
make docker-build docker-push IMG=[Your personal repo]
201205
```
202206

203207
## Reporting Bugs/Feature Requests

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Silence update recommendations for Ginkgo
2+
export ACK_GINKGO_DEPRECATIONS:=1.16.5
3+
14
GIT_COMMIT:=$(shell git describe --dirty --always)
25
GIT_TAG:=$(shell git describe --dirty --always --tags)
36
PKG:=github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/version

config/manager/controller_manager_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ webhook:
88
port: 9443
99
leaderElection:
1010
leaderElect: true
11-
resourceName: db692913.x-k8s.io
11+
resourceName: aws-cloud-map-mcs-controller-for-k8s-lock

integration/janitor/api.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55

66
"github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/cloudmap"
7-
"github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/common"
87
"github.com/aws/aws-sdk-go-v2/aws"
98
sd "github.com/aws/aws-sdk-go-v2/service/servicediscovery"
109
)
@@ -20,9 +19,9 @@ type serviceDiscoveryJanitorApi struct {
2019
janitorFacade SdkJanitorFacade
2120
}
2221

23-
func NewServiceDiscoveryJanitorApiFromConfig(cfg *aws.Config, clusterUtils common.ClusterUtils) ServiceDiscoveryJanitorApi {
22+
func NewServiceDiscoveryJanitorApiFromConfig(cfg *aws.Config) ServiceDiscoveryJanitorApi {
2423
return &serviceDiscoveryJanitorApi{
25-
ServiceDiscoveryApi: cloudmap.NewServiceDiscoveryApiFromConfig(cfg, clusterUtils),
24+
ServiceDiscoveryApi: cloudmap.NewServiceDiscoveryApiFromConfig(cfg),
2625
janitorFacade: NewSdkJanitorFacadeFromConfig(cfg),
2726
}
2827
}

integration/janitor/api_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"testing"
66

77
janitorMock "github.com/aws/aws-cloud-map-mcs-controller-for-k8s/mocks/integration/janitor"
8-
"github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/common"
98
"github.com/aws/aws-cloud-map-mcs-controller-for-k8s/test"
109
"github.com/aws/aws-sdk-go-v2/aws"
1110
sd "github.com/aws/aws-sdk-go-v2/service/servicediscovery"
@@ -14,7 +13,7 @@ import (
1413
)
1514

1615
func TestNewServiceDiscoveryJanitorApiFromConfig(t *testing.T) {
17-
assert.NotNil(t, NewServiceDiscoveryJanitorApiFromConfig(&aws.Config{}, common.ClusterUtils{}))
16+
assert.NotNil(t, NewServiceDiscoveryJanitorApiFromConfig(&aws.Config{}))
1817
}
1918

2019
func TestServiceDiscoveryJanitorApi_DeleteNamespace_HappyCase(t *testing.T) {

integration/janitor/janitor.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"os"
77

88
"github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/cloudmap"
9-
"github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/common"
9+
"github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/model"
1010
"github.com/aws/aws-sdk-go-v2/aws"
1111
"github.com/aws/aws-sdk-go-v2/config"
1212
)
@@ -18,8 +18,10 @@ type CloudMapJanitor interface {
1818
}
1919

2020
type cloudMapJanitor struct {
21-
sdApi ServiceDiscoveryJanitorApi
22-
fail func()
21+
clusterId string
22+
clusterSetId string
23+
sdApi ServiceDiscoveryJanitorApi
24+
fail func()
2325
}
2426

2527
// NewDefaultJanitor returns a new janitor object.
@@ -32,8 +34,10 @@ func NewDefaultJanitor(clusterId string, clusterSetId string) CloudMapJanitor {
3234
}
3335

3436
return &cloudMapJanitor{
35-
sdApi: NewServiceDiscoveryJanitorApiFromConfig(&awsCfg, common.NewClusterUtilsForTest(clusterId, clusterSetId)),
36-
fail: func() { os.Exit(1) },
37+
clusterId: clusterId,
38+
clusterSetId: clusterSetId,
39+
sdApi: NewServiceDiscoveryJanitorApiFromConfig(&awsCfg),
40+
fail: func() { os.Exit(1) },
3741
}
3842
}
3943

@@ -73,7 +77,11 @@ func (j *cloudMapJanitor) Cleanup(ctx context.Context, nsName string) {
7377
}
7478

7579
func (j *cloudMapJanitor) deregisterInstances(ctx context.Context, nsName string, svcName string, svcId string) {
76-
insts, err := j.sdApi.DiscoverInstances(ctx, nsName, svcName)
80+
queryParameters := map[string]string{
81+
model.ClusterSetIdAttr: j.clusterSetId,
82+
}
83+
84+
insts, err := j.sdApi.DiscoverInstances(ctx, nsName, svcName, &queryParameters)
7785
j.checkOrFail(err,
7886
fmt.Sprintf("service has %d instances to clean", len(insts)),
7987
"could not list instances to cleanup")

integration/janitor/janitor_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type testJanitor struct {
2121
}
2222

2323
func TestNewDefaultJanitor(t *testing.T) {
24-
assert.NotNil(t, NewDefaultJanitor(test.ClusterId1, test.ClusterSetId1))
24+
assert.NotNil(t, NewDefaultJanitor(test.ClusterId1, test.ClusterSet))
2525
}
2626

2727
func TestCleanupHappyCase(t *testing.T) {
@@ -32,7 +32,9 @@ func TestCleanupHappyCase(t *testing.T) {
3232
Return(map[string]*model.Namespace{test.HttpNsName: test.GetTestHttpNamespace()}, nil)
3333
tj.mockApi.EXPECT().GetServiceIdMap(context.TODO(), test.HttpNsId).
3434
Return(map[string]string{test.SvcName: test.SvcId}, nil)
35-
tj.mockApi.EXPECT().DiscoverInstances(context.TODO(), test.HttpNsName, test.SvcName).
35+
tj.mockApi.EXPECT().DiscoverInstances(context.TODO(), test.HttpNsName, test.SvcName, &map[string]string{
36+
model.ClusterSetIdAttr: test.ClusterSet,
37+
}).
3638
Return([]types.HttpInstanceSummary{{InstanceId: aws.String(test.EndptId1)}}, nil)
3739

3840
tj.mockApi.EXPECT().DeregisterInstance(context.TODO(), test.SvcId, test.EndptId1).
@@ -67,8 +69,10 @@ func getTestJanitor(t *testing.T) *testJanitor {
6769
failed := false
6870
return &testJanitor{
6971
janitor: &cloudMapJanitor{
70-
sdApi: api,
71-
fail: func() { failed = true },
72+
clusterId: test.ClusterId1,
73+
clusterSetId: test.ClusterSet,
74+
sdApi: api,
75+
fail: func() { failed = true },
7276
},
7377
mockApi: api,
7478
failed: &failed,

integration/kind-test/configs/e2e-coredns-deployment.yaml renamed to integration/kind-test/configs/coredns-deployment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ spec:
5858
- args:
5959
- -conf
6060
- /etc/coredns/Corefile
61-
image: ghcr.io/aws/aws-cloud-map-mcs-controller-for-k8s/coredns-multicluster/coredns:v1.8.4
61+
image: ghcr.io/aws/aws-cloud-map-mcs-controller-for-k8s/coredns-multicluster/coredns:v1.8.6
6262
imagePullPolicy: IfNotPresent
6363
livenessProbe:
6464
failureThreshold: 5
@@ -134,4 +134,4 @@ spec:
134134
- key: Corefile
135135
path: Corefile
136136
name: coredns
137-
name: config-volume
137+
name: config-volume
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: dnsutils
5+
namespace: default
6+
spec:
7+
containers:
8+
- command:
9+
- sleep
10+
- "3600"
11+
image: registry.k8s.io/e2e-test-images/jessie-dnsutils:1.3
12+
name: dnsutils
13+
imagePullPolicy: IfNotPresent
14+
restartPolicy: Always

integration/kind-test/configs/e2e-client-hello.yaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)