Skip to content

Commit 3508116

Browse files
Propagate ClusterID to Cloud Map & Endpoints (#165)
ClusterId, ClusterSetId getting exported to Cloud Map & getting propagated to endpoints as CLUSTER_ID and CLUSTERSET_ID attributes
1 parent b35f6d8 commit 3508116

26 files changed

+713
-57
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.9.2
7+
creationTimestamp: null
8+
name: clusterproperties.about.k8s.io
9+
spec:
10+
group: about.k8s.io
11+
names:
12+
kind: ClusterProperty
13+
listKind: ClusterPropertyList
14+
plural: clusterproperties
15+
singular: clusterproperty
16+
scope: Cluster
17+
versions:
18+
- additionalPrinterColumns:
19+
- jsonPath: .spec.value
20+
name: value
21+
type: string
22+
- jsonPath: .metadata.creationTimestamp
23+
name: age
24+
type: date
25+
name: v1alpha1
26+
schema:
27+
openAPIV3Schema:
28+
description: ClusterProperty is the Schema for the clusterproperties API
29+
properties:
30+
apiVersion:
31+
description: 'APIVersion defines the versioned schema of this representation
32+
of an object. Servers should convert recognized schemas to the latest
33+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
34+
type: string
35+
kind:
36+
description: 'Kind is a string value representing the REST resource this
37+
object represents. Servers may infer this from the endpoint the client
38+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
39+
type: string
40+
metadata:
41+
type: object
42+
spec:
43+
description: ClusterPropertySpec defines the desired state of ClusterProperty
44+
properties:
45+
value:
46+
description: ClusterProperty value
47+
minLength: 1
48+
type: string
49+
required:
50+
- value
51+
type: object
52+
status:
53+
description: ClusterPropertyStatus defines the observed state of ClusterProperty
54+
type: object
55+
type: object
56+
served: true
57+
storage: true
58+
subresources:
59+
status: {}

config/crd/kustomization.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,29 @@
22
# since it depends on service name and namespace that are out of this kustomize package.
33
# It should be run by config/default
44
resources:
5+
- bases/about.k8s.io_clusterproperties.yaml
56
- bases/multicluster.x-k8s.io_serviceexports.yaml
67
- bases/multicluster.x-k8s.io_serviceimports.yaml
78
#+kubebuilder:scaffold:crdkustomizeresource
89

910
patchesStrategicMerge:
1011
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
1112
# patches here are for enabling the conversion webhook for each CRD
13+
#- patches/webhook_in_clusterproperties.yaml
1214
#- patches/webhook_in_serviceexports.yaml
1315
#- patches/webhook_in_serviceimports.yaml
1416
#+kubebuilder:scaffold:crdkustomizewebhookpatch
1517

1618
# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
1719
# patches here are for enabling the CA injection for each CRD
20+
#- patches/cainjection_in_clusterproperties.yaml
1821
#- patches/cainjection_in_serviceexports.yaml
1922
#- patches/cainjection_in_serviceimports.yaml
2023
#+kubebuilder:scaffold:crdkustomizecainjectionpatch
2124

25+
# Patch adds an annotation to pass protected groups approval required to use domain "k8s.io"
26+
- patches/annotation_for_clusterproperties.yaml
27+
2228
# the following config is for teaching kustomize how to do kustomization for CRDs.
2329
configurations:
2430
- kustomizeconfig.yaml
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# The following patch adds an annotation to pass protected groups approval required to use domain "k8s.io"
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
api-approved.kubernetes.io: "https://github.com/kubernetes/enhancements/pull/3084"
7+
name: clusterproperties.about.k8s.io
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# The following patch adds a directive for certmanager to inject CA into the CRD
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
7+
name: clusterproperties.about.k8s.io
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# The following patch enables a conversion webhook for the CRD
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
name: clusterproperties.about.k8s.io
6+
spec:
7+
conversion:
8+
strategy: Webhook
9+
webhook:
10+
clientConfig:
11+
service:
12+
namespace: system
13+
name: webhook-service
14+
path: /convert
15+
conversionReviewVersions:
16+
- v1
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: sample-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: sample-mcs-clustersetid

integration/janitor/api.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ 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"
78
"github.com/aws/aws-sdk-go-v2/aws"
89
sd "github.com/aws/aws-sdk-go-v2/service/servicediscovery"
910
)
@@ -21,7 +22,7 @@ type serviceDiscoveryJanitorApi struct {
2122

2223
func NewServiceDiscoveryJanitorApiFromConfig(cfg *aws.Config) ServiceDiscoveryJanitorApi {
2324
return &serviceDiscoveryJanitorApi{
24-
ServiceDiscoveryApi: cloudmap.NewServiceDiscoveryApiFromConfig(cfg),
25+
ServiceDiscoveryApi: cloudmap.NewServiceDiscoveryApiFromConfig(cfg, common.ClusterUtils{}),
2526
janitorFacade: NewSdkJanitorFacadeFromConfig(cfg),
2627
}
2728
}

integration/shared/scenarios/export_service.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/cloudmap"
11+
"github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/common"
1112
multiclustercontrollers "github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/controllers/multicluster"
1213
"github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/model"
1314
"github.com/aws/aws-sdk-go-v2/aws"
@@ -69,7 +70,7 @@ func NewExportServiceScenario(cfg *aws.Config, nsName string, svcName string, po
6970
NsTTL: time.Second,
7071
SvcTTL: time.Second,
7172
EndptTTL: time.Second,
72-
}),
73+
}, common.ClusterUtils{}),
7374
expectedSvc: model.Service{
7475
Namespace: nsName,
7576
Name: svcName,

main.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"sigs.k8s.io/controller-runtime/pkg/healthz"
2323
"sigs.k8s.io/controller-runtime/pkg/log/zap"
2424

25+
aboutv1alpha1 "github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/apis/about/v1alpha1"
2526
multiclusterv1alpha1 "github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/apis/multicluster/v1alpha1"
2627
multiclustercontrollers "github.com/aws/aws-cloud-map-mcs-controller-for-k8s/pkg/controllers/multicluster"
2728
// +kubebuilder:scaffold:imports
@@ -36,6 +37,8 @@ func init() {
3637
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
3738

3839
utilruntime.Must(multiclusterv1alpha1.AddToScheme(scheme))
40+
41+
utilruntime.Must(aboutv1alpha1.AddToScheme(scheme))
3942
//+kubebuilder:scaffold:scheme
4043
}
4144

@@ -84,21 +87,25 @@ func main() {
8487

8588
log.Info("Running with AWS region", "AWS_REGION", awsCfg.Region)
8689

87-
serviceDiscoveryClient := cloudmap.NewDefaultServiceDiscoveryClient(&awsCfg)
90+
clusterUtils := common.NewClusterUtils(mgr.GetClient())
91+
serviceDiscoveryClient := cloudmap.NewDefaultServiceDiscoveryClient(&awsCfg, clusterUtils)
92+
8893
if err = (&multiclustercontrollers.ServiceExportReconciler{
89-
Client: mgr.GetClient(),
90-
Log: common.NewLogger("controllers", "ServiceExport"),
91-
Scheme: mgr.GetScheme(),
92-
CloudMap: serviceDiscoveryClient,
94+
Client: mgr.GetClient(),
95+
Log: common.NewLogger("controllers", "ServiceExport"),
96+
Scheme: mgr.GetScheme(),
97+
CloudMap: serviceDiscoveryClient,
98+
ClusterUtils: clusterUtils,
9399
}).SetupWithManager(mgr); err != nil {
94100
log.Error(err, "unable to create controller", "controller", "ServiceExport")
95101
os.Exit(1)
96102
}
97103

98104
cloudMapReconciler := &multiclustercontrollers.CloudMapReconciler{
99-
Client: mgr.GetClient(),
100-
Cloudmap: serviceDiscoveryClient,
101-
Log: common.NewLogger("controllers", "Cloudmap"),
105+
Client: mgr.GetClient(),
106+
Cloudmap: serviceDiscoveryClient,
107+
Log: common.NewLogger("controllers", "Cloudmap"),
108+
ClusterUtils: clusterUtils,
102109
}
103110

104111
if err = mgr.Add(cloudMapReconciler); err != nil {

0 commit comments

Comments
 (0)