Skip to content

Commit 3a30bac

Browse files
astaticvoidvanekjar
authored andcommitted
Integrate Cloud Map API
1 parent 5676dcd commit 3a30bac

File tree

10 files changed

+764
-62
lines changed

10 files changed

+764
-62
lines changed

README.md

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# How to build and run
22

3+
Pre-requisite: Create Private DNS Namespace in Cloud Map `demo`
4+
5+
Set region
6+
```
7+
export AWS_REGION=us-west-2
8+
```
9+
310
Spin up a local Kubernetes cluster using `kind`
411

512
```
@@ -19,6 +26,51 @@ Run controller
1926
make run
2027
```
2128

29+
Create a testing deployment
30+
31+
```
32+
# my-deployment.yaml
33+
apiVersion: apps/v1
34+
kind: Deployment
35+
metadata:
36+
namespace: demo
37+
name: nginx-deployment
38+
labels:
39+
app: nginx
40+
spec:
41+
replicas: 5
42+
selector:
43+
matchLabels:
44+
app: nginx
45+
template:
46+
metadata:
47+
labels:
48+
app: nginx
49+
spec:
50+
containers:
51+
- name: nginx
52+
image: nginx:1.14.2
53+
ports:
54+
- containerPort: 80
55+
```
56+
57+
Create a testing Service
58+
59+
```
60+
# my-service.yaml
61+
kind: Service
62+
apiVersion: v1
63+
metadata:
64+
namespace: demo
65+
name: my-service-name
66+
spec:
67+
selector:
68+
app: nginx
69+
ports:
70+
- port: 8080
71+
targetPort: 80
72+
```
73+
2274
Create a testing ServiceExport resource
2375

2476
```
@@ -31,15 +83,24 @@ metadata:
3183
name: my-service-name
3284
```
3385

34-
Apply config file
86+
Apply config files
3587

3688
```
3789
kubectl create namespace demo
90+
kubectl apply -f my-deployment.yaml
91+
kubectl apply -f my-service.yaml
3892
kubectl apply -f my-export.yaml
3993
```
4094

4195
Check running controller if it correctly detects newly created resource
4296

4397
```
44-
2021-05-10T18:23:28.674-0700 ERROR controllers.ServiceExport no service found for ServiceExport {"serviceexport": "demo/my-service-name", "Namespace": "demo", "Name": "my-service-name", "error": "Service \"my-service-name\" not found"}
98+
2021-07-09T14:31:26.933-0700 INFO controllers.ServiceExport updating Cloud Map service {"serviceexport": "demo/my-service-name", "namespace": "demo", "name": "my-service-name"}
99+
2021-07-09T14:31:26.933-0700 INFO cloudmap fetching a service {"namespaceName": "demo", "serviceName": "my-service-name"}
100+
2021-07-09T14:31:27.341-0700 INFO cloudmap creating a new service {"namespace": "demo", "name": "my-service-name"}
101+
```
102+
103+
# How to generate mocks and run unit tests
104+
```
105+
make test
45106
```

aws-k8s-mcs-controller.REMOVED.git-id

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

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ module github.com/aws/aws-k8s-mcs-controller
33
go 1.15
44

55
require (
6+
github.com/aws/aws-sdk-go-v2 v1.8.1
7+
github.com/aws/aws-sdk-go-v2/config v1.6.1
8+
github.com/aws/aws-sdk-go-v2/service/servicediscovery v1.7.3
69
github.com/go-logr/logr v0.3.0
710
github.com/golang/mock v1.6.0
811
github.com/onsi/ginkgo v1.14.1

go.sum

Lines changed: 36 additions & 7 deletions
Large diffs are not rendered by default.

main.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ limitations under the License.
1717
package main
1818

1919
import (
20+
"context"
2021
"flag"
21-
"github.com/aws/aws-k8s-mcs-controller/pkg/cloudmap"
22+
23+
"github.com/aws/aws-sdk-go-v2/config"
2224
"os"
2325

26+
"github.com/aws/aws-k8s-mcs-controller/pkg/cloudmap"
27+
2428
// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
2529
// to ensure that exec-entrypoint and run can make use of them.
2630
_ "k8s.io/client-go/plugin/pkg/client/auth"
@@ -79,11 +83,20 @@ func main() {
7983
os.Exit(1)
8084
}
8185

86+
// TODO: configure session
87+
awsCfg, err := config.LoadDefaultConfig(context.TODO(),
88+
config.WithRegion(os.Getenv("AWS_REGION")),
89+
)
90+
if err != nil {
91+
setupLog.Error(err, "unable to configure AWS session")
92+
os.Exit(1)
93+
}
94+
8295
if err = (&controllers.ServiceExportReconciler{
8396
Client: mgr.GetClient(),
8497
Log: ctrl.Log.WithName("controllers").WithName("ServiceExport"),
8598
Scheme: mgr.GetScheme(),
86-
Cloudmap: &cloudmap.ClientMock{Log: ctrl.Log.WithName("cloudmap")},
99+
Cloudmap: cloudmap.NewServiceDiscoveryClient(&awsCfg),
87100
}).SetupWithManager(mgr); err != nil {
88101
setupLog.Error(err, "unable to create controller", "controller", "ServiceExport")
89102
os.Exit(1)

0 commit comments

Comments
 (0)