Skip to content

Commit 9894a3a

Browse files
Fix integration tests + update docs (#178)
* Added managed by label - issue 110 * fixed integration tests * update docs + add samples * updated readme + contributing * update make install expected output * update contributing
1 parent 3508116 commit 9894a3a

File tree

12 files changed

+114
-17
lines changed

12 files changed

+114
-17
lines changed

CONTRIBUTING.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,24 @@ kubectl create namespace example
7474

7575
#### Run the controller from outside the cluster
7676

77-
To register the custom CRDs (`ServiceImport`, `ServiceExport`) in the cluster and create installers:
77+
To register the custom CRDs (`ClusterProperties`, `ServiceImport`, `ServiceExport`) in the cluster and create installers:
7878
```sh
7979
make install
8080
# ...
81+
# customresourcedefinition.apiextensions.k8s.io/clusterproperties.about.k8s.io created
8182
# customresourcedefinition.apiextensions.k8s.io/serviceexports.multicluster.x-k8s.io created
8283
# customresourcedefinition.apiextensions.k8s.io/serviceimports.multicluster.x-k8s.io created
8384
```
8485

86+
Register a unique `id.k8s.io` and `clusterset.k8s.io` in your cluster:
87+
```bash
88+
kubectl apply -f samples/example-clusterproperty.yaml
89+
# clusterproperty.about.k8s.io/id.k8s.io created
90+
# clusterproperty.about.k8s.io/clusterset.k8s.io created
91+
```
92+
> **Note:** If you are creating multiple clusters, ensure you create unique `id.k8s.io` identifiers for each cluster.
93+
94+
8595
To run the controller, run the following command. The controller runs in an infinite loop so open another terminal to create CRDs.
8696
```sh
8797
make run

README.md

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ Install the The CoreDNS multicluster plugin into each participating cluster. The
4242
To install the plugin, run the following commands.
4343

4444
```bash
45-
kubectl apply -k "github.com/aws/aws-cloud-map-mcs-controller-for-k8s/samples/coredns-clusterrole.yaml
46-
kubectl apply -k "github.com/aws/aws-cloud-map-mcs-controller-for-k8s/samples/coredns-configmap.yaml
47-
kubectl apply -k "github.com/aws/aws-cloud-map-mcs-controller-for-k8s/samples/coredns-deployment.yaml
45+
kubectl apply -k "github.com/aws/aws-cloud-map-mcs-controller-for-k8s/samples/coredns-clusterrole.yaml"
46+
kubectl apply -k "github.com/aws/aws-cloud-map-mcs-controller-for-k8s/samples/coredns-configmap.yaml"
47+
kubectl apply -k "github.com/aws/aws-cloud-map-mcs-controller-for-k8s/samples/coredns-deployment.yaml"
4848
```
4949

5050
### Install Controller
@@ -63,6 +63,45 @@ The controller must have sufficient IAM permissions to perform required Cloud Ma
6363

6464
## Usage
6565

66+
### Configure `id.k8s.io` and `clusterset.k8s.io`
67+
68+
`id.k8s.io` is a unique identifier that uniquely identifies a cluster.
69+
70+
`clusterset.k8s.io` is a unique identifier that uniquely identifies the set of clusters in your multicluster. This will be the same across all clusters in the set.
71+
72+
```yaml
73+
apiVersion: about.k8s.io/v1alpha1
74+
kind: ClusterProperty
75+
metadata:
76+
name: id.k8s.io
77+
spec:
78+
value: [Your cluster identifier]
79+
---
80+
apiVersion: about.k8s.io/v1alpha1
81+
kind: ClusterProperty
82+
metadata:
83+
name: clusterset.k8s.io
84+
spec:
85+
value: [Your cluster set identifier]
86+
```
87+
88+
**Example:**
89+
```yaml
90+
apiVersion: about.k8s.io/v1alpha1
91+
kind: ClusterProperty
92+
metadata:
93+
name: id.k8s.io
94+
spec:
95+
value: my-first-cluster
96+
---
97+
apiVersion: about.k8s.io/v1alpha1
98+
kind: ClusterProperty
99+
metadata:
100+
name: clusterset.k8s.io
101+
spec:
102+
value: my-clusterset
103+
```
104+
66105
### Export services
67106
68107
Then assuming you already have a Service installed, apply a `ServiceExport` yaml to the cluster in which you want to export a service. This can be done for each service you want to export.

integration/janitor/api.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/cloudmap"
77
"github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/common"
8+
"github.com/aws/aws-cloud-map-mcs-controller-for-k8s/test"
89
"github.com/aws/aws-sdk-go-v2/aws"
910
sd "github.com/aws/aws-sdk-go-v2/service/servicediscovery"
1011
)
@@ -22,7 +23,7 @@ type serviceDiscoveryJanitorApi struct {
2223

2324
func NewServiceDiscoveryJanitorApiFromConfig(cfg *aws.Config) ServiceDiscoveryJanitorApi {
2425
return &serviceDiscoveryJanitorApi{
25-
ServiceDiscoveryApi: cloudmap.NewServiceDiscoveryApiFromConfig(cfg, common.ClusterUtils{}),
26+
ServiceDiscoveryApi: cloudmap.NewServiceDiscoveryApiFromConfig(cfg, common.NewClusterUtilsForTest(test.ClusterId, test.ClusterSetId)),
2627
janitorFacade: NewSdkJanitorFacadeFromConfig(cfg),
2728
}
2829
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# An example object of `id.k8s.io ClusterProperty`
2+
3+
apiVersion: about.k8s.io/v1alpha1
4+
kind: ClusterProperty
5+
metadata:
6+
name: id.k8s.io
7+
spec:
8+
value: test-mcs-clusterId
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# An example object of `clusterset.k8s.io ClusterProperty`:
2+
3+
apiVersion: about.k8s.io/v1alpha1
4+
kind: ClusterProperty
5+
metadata:
6+
name: clusterset.k8s.io
7+
spec:
8+
value: test-mcs-clusterSetId

integration/kind-test/scripts/run-tests.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
source ./integration/kind-test/scripts/common.sh
66

7+
$KUBECTL_BIN apply -f "$CONFIGS/e2e-clusterId.yaml"
8+
$KUBECTL_BIN apply -f "$CONFIGS/e2e-clusterSetId.yaml"
9+
710
$KUBECTL_BIN apply -f "$CONFIGS/e2e-deployment.yaml"
811
$KUBECTL_BIN apply -f "$CONFIGS/e2e-service.yaml"
912
$KUBECTL_BIN apply -f "$CONFIGS/e2e-export.yaml"

integration/shared/scenarios/export_service.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/common"
1212
multiclustercontrollers "github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/controllers/multicluster"
1313
"github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/model"
14+
"github.com/aws/aws-cloud-map-mcs-controller-for-k8s/test"
1415
"github.com/aws/aws-sdk-go-v2/aws"
1516
v1 "k8s.io/api/core/v1"
1617
"k8s.io/apimachinery/pkg/util/wait"
@@ -59,6 +60,8 @@ func NewExportServiceScenario(cfg *aws.Config, nsName string, svcName string, po
5960
Protocol: string(v1.ProtocolTCP),
6061
},
6162
EndpointPort: endpointPort,
63+
ClusterId: test.ClusterId,
64+
ClusterSetId: test.ClusterSetId,
6265
ServiceType: model.ClusterSetIPType, // in scenario, we assume ClusterSetIP type
6366
Attributes: make(map[string]string),
6467
})
@@ -70,7 +73,7 @@ func NewExportServiceScenario(cfg *aws.Config, nsName string, svcName string, po
7073
NsTTL: time.Second,
7174
SvcTTL: time.Second,
7275
EndptTTL: time.Second,
73-
}, common.ClusterUtils{}),
76+
}, common.NewClusterUtilsForTest(test.ClusterId, test.ClusterSetId)),
7477
expectedSvc: model.Service{
7578
Namespace: nsName,
7679
Name: svcName,

pkg/cloudmap/api_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
)
2424

2525
func TestNewServiceDiscoveryApi(t *testing.T) {
26-
sdc := NewServiceDiscoveryApiFromConfig(&aws.Config{}, common.ClusterUtils{})
26+
sdc := NewServiceDiscoveryApiFromConfig(&aws.Config{}, common.NewClusterUtilsForTest(test.ClusterId, test.ClusterSetId))
2727
assert.NotNil(t, sdc)
2828
}
2929

@@ -107,7 +107,7 @@ func TestServiceDiscoveryApi_DiscoverInstances_HappyCase(t *testing.T) {
107107
HealthStatus: types.HealthStatusFilterAll,
108108
MaxResults: aws.Int32(1000),
109109
QueryParameters: map[string]string{
110-
model.ClusterSetIdAttr: test.ClustersetId,
110+
model.ClusterSetIdAttr: test.ClusterSetId,
111111
},
112112
}).
113113
Return(&sd.DiscoverInstancesOutput{

pkg/cloudmap/client_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type testSdClient struct {
2424
}
2525

2626
func TestNewServiceDiscoveryClient(t *testing.T) {
27-
sdc := NewDefaultServiceDiscoveryClient(&aws.Config{}, common.ClusterUtils{})
27+
sdc := NewDefaultServiceDiscoveryClient(&aws.Config{}, common.NewClusterUtilsForTest(test.ClusterId, test.ClusterSetId))
2828
assert.NotNil(t, sdc)
2929
}
3030

@@ -284,7 +284,7 @@ func TestServiceDiscoveryClient_RegisterEndpoints(t *testing.T) {
284284

285285
attrs1 := map[string]string{
286286
model.ClusterIdAttr: test.ClusterId,
287-
model.ClusterSetIdAttr: test.ClustersetId,
287+
model.ClusterSetIdAttr: test.ClusterSetId,
288288
model.EndpointIpv4Attr: test.EndptIp1,
289289
model.EndpointPortAttr: test.PortStr1,
290290
model.EndpointPortNameAttr: test.PortName1,
@@ -297,7 +297,7 @@ func TestServiceDiscoveryClient_RegisterEndpoints(t *testing.T) {
297297
}
298298
attrs2 := map[string]string{
299299
model.ClusterIdAttr: test.ClusterId,
300-
model.ClusterSetIdAttr: test.ClustersetId,
300+
model.ClusterSetIdAttr: test.ClusterSetId,
301301
model.EndpointIpv4Attr: test.EndptIp2,
302302
model.EndpointPortAttr: test.PortStr2,
303303
model.EndpointPortNameAttr: test.PortName2,
@@ -369,7 +369,7 @@ func getHttpInstanceSummaryForTest() []types.HttpInstanceSummary {
369369
InstanceId: aws.String(test.EndptId1),
370370
Attributes: map[string]string{
371371
model.ClusterIdAttr: test.ClusterId,
372-
model.ClusterSetIdAttr: test.ClustersetId,
372+
model.ClusterSetIdAttr: test.ClusterSetId,
373373
model.EndpointIpv4Attr: test.EndptIp1,
374374
model.EndpointPortAttr: test.PortStr1,
375375
model.EndpointPortNameAttr: test.PortName1,
@@ -385,7 +385,7 @@ func getHttpInstanceSummaryForTest() []types.HttpInstanceSummary {
385385
InstanceId: aws.String(test.EndptId2),
386386
Attributes: map[string]string{
387387
model.ClusterIdAttr: test.ClusterId,
388-
model.ClusterSetIdAttr: test.ClustersetId,
388+
model.ClusterSetIdAttr: test.ClusterSetId,
389389
model.EndpointIpv4Attr: test.EndptIp2,
390390
model.EndpointPortAttr: test.PortStr2,
391391
model.EndpointPortNameAttr: test.PortName2,

pkg/common/cluster.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ func NewClusterUtils(client client.Client) ClusterUtils {
2828
}
2929
}
3030

31+
// constructor for tests
32+
func NewClusterUtilsForTest(clusterId string, clusterSetId string) ClusterUtils {
33+
return ClusterUtils{
34+
clusterId: clusterId,
35+
clusterSetId: clusterSetId,
36+
}
37+
}
38+
3139
// retrieve the clusterId from the local field. If not set, retrieve from client
3240
func (r *ClusterUtils) GetClusterId(ctx context.Context) (string, error) {
3341
if r.clusterId != "" {

0 commit comments

Comments
 (0)