From e2e43856c598589761e0a81369077c86ae22b6ee Mon Sep 17 00:00:00 2001 From: Ashwin Venkatesh Date: Tue, 26 Oct 2021 09:54:05 -0400 Subject: [PATCH] Rename service-exports -> partition-exports --- ...viceexports.yaml => partitionexports.yaml} | 2 +- .../templates/controller-clusterrole.yaml | 4 +- ...exports.yaml => crd-partitionexports.yaml} | 14 +- ...exports.bats => crd-partitionexports.bats} | 8 +- control-plane/PROJECT | 2 +- control-plane/api/common/common.go | 4 +- ...rts_types.go => partitionexports_types.go} | 67 ++++---- ...test.go => partitionexports_types_test.go} | 147 ++++++++-------- ...webhook.go => partitionexports_webhook.go} | 34 ++-- ...st.go => partitionexports_webhook_test.go} | 43 ++--- .../api/v1alpha1/zz_generated.deepcopy.go | 162 +++++++++--------- ...onsul.hashicorp.com_partitionexports.yaml} | 14 +- control-plane/config/crd/kustomization.yaml | 6 +- .../cainjection_in_serviceexports.yaml | 8 - ....yaml => webhook_in_partitionexports.yaml} | 2 +- ....yaml => partitionexport_editor_role.yaml} | 8 +- ....yaml => partitionexport_viewer_role.yaml} | 8 +- control-plane/config/rbac/role.yaml | 12 +- ...l => consul_v1alpha1_partitionexport.yaml} | 4 +- control-plane/config/webhook/manifests.yaml | 18 +- .../controller/partitionexports_controller.go | 40 +++++ .../controller/serviceexports_controller.go | 40 ----- control-plane/go.mod | 2 +- control-plane/go.sum | 4 +- .../subcommand/controller/command.go | 13 +- 25 files changed, 332 insertions(+), 334 deletions(-) rename acceptance/tests/fixtures/crds/{serviceexports.yaml => partitionexports.yaml} (87%) rename charts/consul/templates/{crd-serviceexports.yaml => crd-partitionexports.yaml} (93%) rename charts/consul/test/unit/{crd-serviceexports.bats => crd-partitionexports.bats} (69%) rename control-plane/api/v1alpha1/{serviceexports_types.go => partitionexports_types.go} (64%) rename control-plane/api/v1alpha1/{serviceexports_types_test.go => partitionexports_types_test.go} (52%) rename control-plane/api/v1alpha1/{serviceexports_webhook.go => partitionexports_webhook.go} (51%) rename control-plane/api/v1alpha1/{serviceexports_webhook_test.go => partitionexports_webhook_test.go} (67%) rename control-plane/config/crd/bases/{consul.hashicorp.com_serviceexports.yaml => consul.hashicorp.com_partitionexports.yaml} (93%) delete mode 100644 control-plane/config/crd/patches/cainjection_in_serviceexports.yaml rename control-plane/config/crd/patches/{webhook_in_serviceexports.yaml => webhook_in_partitionexports.yaml} (92%) rename control-plane/config/rbac/{serviceexport_editor_role.yaml => partitionexport_editor_role.yaml} (66%) rename control-plane/config/rbac/{serviceexport_viewer_role.yaml => partitionexport_viewer_role.yaml} (62%) rename control-plane/config/samples/{consul_v1alpha1_serviceexport.yaml => consul_v1alpha1_partitionexport.yaml} (64%) create mode 100644 control-plane/controller/partitionexports_controller.go delete mode 100644 control-plane/controller/serviceexports_controller.go diff --git a/acceptance/tests/fixtures/crds/serviceexports.yaml b/acceptance/tests/fixtures/crds/partitionexports.yaml similarity index 87% rename from acceptance/tests/fixtures/crds/serviceexports.yaml rename to acceptance/tests/fixtures/crds/partitionexports.yaml index 8ae095cd8e..d6159310cf 100644 --- a/acceptance/tests/fixtures/crds/serviceexports.yaml +++ b/acceptance/tests/fixtures/crds/partitionexports.yaml @@ -1,5 +1,5 @@ apiVersion: consul.hashicorp.com/v1alpha1 -kind: ServiceExports +kind: PartitionExports metadata: name: exports spec: diff --git a/charts/consul/templates/controller-clusterrole.yaml b/charts/consul/templates/controller-clusterrole.yaml index ecff0b7a3a..993768811c 100644 --- a/charts/consul/templates/controller-clusterrole.yaml +++ b/charts/consul/templates/controller-clusterrole.yaml @@ -17,7 +17,7 @@ rules: - serviceresolvers - proxydefaults - meshes - - serviceexports + - partitionexports - servicerouters - servicesplitters - serviceintentions @@ -38,7 +38,7 @@ rules: - serviceresolvers/status - proxydefaults/status - meshes/status - - serviceexports/status + - partitionexports/status - servicerouters/status - servicesplitters/status - serviceintentions/status diff --git a/charts/consul/templates/crd-serviceexports.yaml b/charts/consul/templates/crd-partitionexports.yaml similarity index 93% rename from charts/consul/templates/crd-serviceexports.yaml rename to charts/consul/templates/crd-partitionexports.yaml index 2f6c3f3cc3..a39dcaad0a 100644 --- a/charts/consul/templates/crd-serviceexports.yaml +++ b/charts/consul/templates/crd-partitionexports.yaml @@ -6,7 +6,7 @@ metadata: annotations: controller-gen.kubebuilder.io/version: v0.6.0 creationTimestamp: null - name: serviceexports.consul.hashicorp.com + name: partitionexports.consul.hashicorp.com labels: app: {{ template "consul.name" . }} chart: {{ template "consul.chart" . }} @@ -16,10 +16,10 @@ metadata: spec: group: consul.hashicorp.com names: - kind: ServiceExports - listKind: ServiceExportsList - plural: serviceexports - singular: serviceexports + kind: PartitionExports + listKind: PartitionExportsList + plural: partitionexports + singular: partitionexports scope: Namespaced versions: - additionalPrinterColumns: @@ -38,7 +38,7 @@ spec: name: v1alpha1 schema: openAPIV3Schema: - description: ServiceExports is the Schema for the serviceexports API + description: PartitionExports is the Schema for the partitionexports API properties: apiVersion: description: 'APIVersion defines the versioned schema of this representation @@ -53,7 +53,7 @@ spec: metadata: type: object spec: - description: ServiceExportsSpec defines the desired state of ServiceExports + description: PartitionExportsSpec defines the desired state of PartitionExports properties: services: description: Services is a list of services to be exported and the diff --git a/charts/consul/test/unit/crd-serviceexports.bats b/charts/consul/test/unit/crd-partitionexports.bats similarity index 69% rename from charts/consul/test/unit/crd-serviceexports.bats rename to charts/consul/test/unit/crd-partitionexports.bats index 21496173d7..35463eea29 100644 --- a/charts/consul/test/unit/crd-serviceexports.bats +++ b/charts/consul/test/unit/crd-partitionexports.bats @@ -2,17 +2,17 @@ load _helpers -@test "serviceExports/CustomerResourceDefinition: disabled by default" { +@test "partitionExports/CustomerResourceDefinition: disabled by default" { cd `chart_dir` assert_empty helm template \ - -s templates/crd-serviceexports.yaml \ + -s templates/crd-partitionexports.yaml \ . } -@test "serviceExports/CustomerResourceDefinition: enabled with controller.enabled=true" { +@test "partitionExports/CustomerResourceDefinition: enabled with controller.enabled=true" { cd `chart_dir` local actual=$(helm template \ - -s templates/crd-serviceexports.yaml \ + -s templates/crd-partitionexports.yaml \ --set 'controller.enabled=true' \ . | tee /dev/stderr | # The generated CRDs have "---" at the top which results in two objects diff --git a/control-plane/PROJECT b/control-plane/PROJECT index 273962cc9e..9e26de1f52 100644 --- a/control-plane/PROJECT +++ b/control-plane/PROJECT @@ -56,7 +56,7 @@ resources: - controller: true domain: hashicorp.com group: consul - kind: ServiceExport + kind: PartitionExport path: github.com/hashicorp/consul-k8s/api/v1alpha1 version: v1alpha1 version: "3" diff --git a/control-plane/api/common/common.go b/control-plane/api/common/common.go index e6b9e5df9a..a44f527472 100644 --- a/control-plane/api/common/common.go +++ b/control-plane/api/common/common.go @@ -8,14 +8,14 @@ const ( ServiceRouter string = "servicerouter" ServiceSplitter string = "servicesplitter" ServiceIntentions string = "serviceintentions" - ServiceExports string = "serviceexports" + PartitionExports string = "partitionexports" IngressGateway string = "ingressgateway" TerminatingGateway string = "terminatinggateway" Global string = "global" Mesh string = "mesh" - Exports string = "exports" DefaultConsulNamespace string = "default" + DefaultConsulPartition string = "default" WildcardNamespace string = "*" SourceKey string = "external-source" diff --git a/control-plane/api/v1alpha1/serviceexports_types.go b/control-plane/api/v1alpha1/partitionexports_types.go similarity index 64% rename from control-plane/api/v1alpha1/serviceexports_types.go rename to control-plane/api/v1alpha1/partitionexports_types.go index 75c00b9ebe..9c20377807 100644 --- a/control-plane/api/v1alpha1/serviceexports_types.go +++ b/control-plane/api/v1alpha1/partitionexports_types.go @@ -10,38 +10,38 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -const ServiceExportsKubeKind = "serviceexports" +const PartitionExportsKubeKind = "partitionexports" func init() { - SchemeBuilder.Register(&ServiceExports{}, &ServiceExportsList{}) + SchemeBuilder.Register(&PartitionExports{}, &PartitionExportsList{}) } //+kubebuilder:object:root=true //+kubebuilder:subresource:status -// ServiceExports is the Schema for the serviceexports API +// PartitionExports is the Schema for the partitionexports API // +kubebuilder:printcolumn:name="Synced",type="string",JSONPath=".status.conditions[?(@.type==\"Synced\")].status",description="The sync status of the resource with Consul" // +kubebuilder:printcolumn:name="Last Synced",type="date",JSONPath=".status.lastSyncedTime",description="The last successful synced time of the resource with Consul" // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="The age of the resource" -type ServiceExports struct { +type PartitionExports struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec ServiceExportsSpec `json:"spec,omitempty"` + Spec PartitionExportsSpec `json:"spec,omitempty"` Status `json:"status,omitempty"` } //+kubebuilder:object:root=true -// ServiceExportsList contains a list of ServiceExports -type ServiceExportsList struct { +// PartitionExportsList contains a list of PartitionExports +type PartitionExportsList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty"` - Items []ServiceExports `json:"items"` + Items []PartitionExports `json:"items"` } -// ServiceExportsSpec defines the desired state of ServiceExports -type ServiceExportsSpec struct { +// PartitionExportsSpec defines the desired state of PartitionExports +type PartitionExportsSpec struct { // Services is a list of services to be exported and the list of partitions // to expose them to. Services []ExportedService `json:"services,omitempty"` @@ -66,15 +66,15 @@ type ServiceConsumer struct { Partition string `json:"partition,omitempty"` } -func (in *ServiceExports) GetObjectMeta() metav1.ObjectMeta { +func (in *PartitionExports) GetObjectMeta() metav1.ObjectMeta { return in.ObjectMeta } -func (in *ServiceExports) AddFinalizer(name string) { +func (in *PartitionExports) AddFinalizer(name string) { in.ObjectMeta.Finalizers = append(in.Finalizers(), name) } -func (in *ServiceExports) RemoveFinalizer(name string) { +func (in *PartitionExports) RemoveFinalizer(name string) { var newFinalizers []string for _, oldF := range in.Finalizers() { if oldF != name { @@ -84,35 +84,35 @@ func (in *ServiceExports) RemoveFinalizer(name string) { in.ObjectMeta.Finalizers = newFinalizers } -func (in *ServiceExports) Finalizers() []string { +func (in *PartitionExports) Finalizers() []string { return in.ObjectMeta.Finalizers } -func (in *ServiceExports) ConsulKind() string { - return capi.ServiceExports +func (in *PartitionExports) ConsulKind() string { + return capi.PartitionExports } -func (in *ServiceExports) ConsulGlobalResource() bool { +func (in *PartitionExports) ConsulGlobalResource() bool { return true } -func (in *ServiceExports) ConsulMirroringNS() string { +func (in *PartitionExports) ConsulMirroringNS() string { return common.DefaultConsulNamespace } -func (in *ServiceExports) KubeKind() string { - return ServiceExportsKubeKind +func (in *PartitionExports) KubeKind() string { + return PartitionExportsKubeKind } -func (in *ServiceExports) ConsulName() string { +func (in *PartitionExports) ConsulName() string { return in.ObjectMeta.Name } -func (in *ServiceExports) KubernetesName() string { +func (in *PartitionExports) KubernetesName() string { return in.ObjectMeta.Name } -func (in *ServiceExports) SetSyncedCondition(status corev1.ConditionStatus, reason, message string) { +func (in *PartitionExports) SetSyncedCondition(status corev1.ConditionStatus, reason, message string) { in.Status.Conditions = Conditions{ { Type: ConditionSynced, @@ -124,11 +124,11 @@ func (in *ServiceExports) SetSyncedCondition(status corev1.ConditionStatus, reas } } -func (in *ServiceExports) SetLastSyncedTime(time *metav1.Time) { +func (in *PartitionExports) SetLastSyncedTime(time *metav1.Time) { in.Status.LastSyncedTime = time } -func (in *ServiceExports) SyncedCondition() (status corev1.ConditionStatus, reason, message string) { +func (in *PartitionExports) SyncedCondition() (status corev1.ConditionStatus, reason, message string) { cond := in.Status.GetCondition(ConditionSynced) if cond == nil { return corev1.ConditionUnknown, "", "" @@ -136,7 +136,7 @@ func (in *ServiceExports) SyncedCondition() (status corev1.ConditionStatus, reas return cond.Status, cond.Reason, cond.Message } -func (in *ServiceExports) SyncedConditionStatus() corev1.ConditionStatus { +func (in *PartitionExports) SyncedConditionStatus() corev1.ConditionStatus { cond := in.Status.GetCondition(ConditionSynced) if cond == nil { return corev1.ConditionUnknown @@ -144,12 +144,13 @@ func (in *ServiceExports) SyncedConditionStatus() corev1.ConditionStatus { return cond.Status } -func (in *ServiceExports) ToConsul(datacenter string) api.ConfigEntry { +func (in *PartitionExports) ToConsul(datacenter string) api.ConfigEntry { var services []capi.ExportedService for _, service := range in.Spec.Services { services = append(services, service.toConsul()) } - return &capi.ServiceExportsConfigEntry{ + return &capi.PartitionExportsConfigEntry{ + Name: in.Name, Services: services, Meta: meta(datacenter), } @@ -167,19 +168,19 @@ func (in *ExportedService) toConsul() capi.ExportedService { } } -func (in *ServiceExports) MatchesConsul(candidate api.ConfigEntry) bool { - configEntry, ok := candidate.(*capi.ServiceExportsConfigEntry) +func (in *PartitionExports) MatchesConsul(candidate api.ConfigEntry) bool { + configEntry, ok := candidate.(*capi.PartitionExportsConfigEntry) if !ok { return false } // No datacenter is passed to ToConsul as we ignore the Meta field when checking for equality. - return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.ServiceExportsConfigEntry{}, "Partition", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty()) + return cmp.Equal(in.ToConsul(""), configEntry, cmpopts.IgnoreFields(capi.PartitionExportsConfigEntry{}, "Partition", "Meta", "ModifyIndex", "CreateIndex"), cmpopts.IgnoreUnexported(), cmpopts.EquateEmpty()) } -func (in *ServiceExports) Validate(_ bool) error { +func (in *PartitionExports) Validate(_ bool) error { return nil } -func (in *ServiceExports) DefaultNamespaceFields(_ bool, _ string, _ bool, _ string) { +func (in *PartitionExports) DefaultNamespaceFields(_ bool, _ string, _ bool, _ string) { } diff --git a/control-plane/api/v1alpha1/serviceexports_types_test.go b/control-plane/api/v1alpha1/partitionexports_types_test.go similarity index 52% rename from control-plane/api/v1alpha1/serviceexports_types_test.go rename to control-plane/api/v1alpha1/partitionexports_types_test.go index 97cc0bd6bd..dc0898da66 100644 --- a/control-plane/api/v1alpha1/serviceexports_types_test.go +++ b/control-plane/api/v1alpha1/partitionexports_types_test.go @@ -12,20 +12,21 @@ import ( ) // Test MatchesConsul for cases that should return true. -func TestServiceExports_MatchesConsul(t *testing.T) { +func TestPartitionExports_MatchesConsul(t *testing.T) { cases := map[string]struct { - Ours ServiceExports + Ours PartitionExports Theirs capi.ConfigEntry Matches bool }{ "empty fields matches": { - Ours: ServiceExports{ + Ours: PartitionExports{ ObjectMeta: metav1.ObjectMeta{ - Name: common.Exports, + Name: common.DefaultConsulPartition, }, - Spec: ServiceExportsSpec{}, + Spec: PartitionExportsSpec{}, }, - Theirs: &capi.ServiceExportsConfigEntry{ + Theirs: &capi.PartitionExportsConfigEntry{ + Name: common.DefaultConsulPartition, CreateIndex: 1, ModifyIndex: 2, Meta: map[string]string{ @@ -36,11 +37,11 @@ func TestServiceExports_MatchesConsul(t *testing.T) { Matches: true, }, "all fields set matches": { - Ours: ServiceExports{ + Ours: PartitionExports{ ObjectMeta: metav1.ObjectMeta{ - Name: common.Exports, + Name: common.DefaultConsulPartition, }, - Spec: ServiceExportsSpec{ + Spec: PartitionExportsSpec{ Services: []ExportedService{ { Name: "service-frontend", @@ -69,8 +70,8 @@ func TestServiceExports_MatchesConsul(t *testing.T) { }, }, }, - Theirs: &capi.ServiceExportsConfigEntry{ - Partition: "default", + Theirs: &capi.PartitionExportsConfigEntry{ + Name: common.DefaultConsulPartition, Services: []capi.ExportedService{ { Name: "service-frontend", @@ -107,15 +108,15 @@ func TestServiceExports_MatchesConsul(t *testing.T) { Matches: true, }, "mismatched types does not match": { - Ours: ServiceExports{ + Ours: PartitionExports{ ObjectMeta: metav1.ObjectMeta{ - Name: common.Exports, + Name: common.DefaultConsulPartition, }, - Spec: ServiceExportsSpec{}, + Spec: PartitionExportsSpec{}, }, Theirs: &capi.ServiceConfigEntry{ - Name: common.Exports, - Kind: capi.ServiceExports, + Name: common.DefaultConsulPartition, + Kind: capi.PartitionExports, }, Matches: false, }, @@ -127,19 +128,20 @@ func TestServiceExports_MatchesConsul(t *testing.T) { } } -func TestServiceExports_ToConsul(t *testing.T) { +func TestPartitionExports_ToConsul(t *testing.T) { cases := map[string]struct { - Ours ServiceExports - Exp *capi.ServiceExportsConfigEntry + Ours PartitionExports + Exp *capi.PartitionExportsConfigEntry }{ "empty fields": { - Ours: ServiceExports{ + Ours: PartitionExports{ ObjectMeta: metav1.ObjectMeta{ - Name: common.Exports, + Name: common.DefaultConsulPartition, }, - Spec: ServiceExportsSpec{}, + Spec: PartitionExportsSpec{}, }, - Exp: &capi.ServiceExportsConfigEntry{ + Exp: &capi.PartitionExportsConfigEntry{ + Name: common.DefaultConsulPartition, Meta: map[string]string{ common.SourceKey: common.SourceValue, common.DatacenterKey: "datacenter", @@ -147,11 +149,11 @@ func TestServiceExports_ToConsul(t *testing.T) { }, }, "every field set": { - Ours: ServiceExports{ + Ours: PartitionExports{ ObjectMeta: metav1.ObjectMeta{ - Name: common.Exports, + Name: common.DefaultConsulPartition, }, - Spec: ServiceExportsSpec{ + Spec: PartitionExportsSpec{ Services: []ExportedService{ { Name: "service-frontend", @@ -180,7 +182,8 @@ func TestServiceExports_ToConsul(t *testing.T) { }, }, }, - Exp: &capi.ServiceExportsConfigEntry{ + Exp: &capi.PartitionExportsConfigEntry{ + Name: common.DefaultConsulPartition, Services: []capi.ExportedService{ { Name: "service-frontend", @@ -217,49 +220,49 @@ func TestServiceExports_ToConsul(t *testing.T) { for name, c := range cases { t.Run(name, func(t *testing.T) { act := c.Ours.ToConsul("datacenter") - serviceExports, ok := act.(*capi.ServiceExportsConfigEntry) + partitionExports, ok := act.(*capi.PartitionExportsConfigEntry) require.True(t, ok, "could not cast") - require.Equal(t, c.Exp, serviceExports) + require.Equal(t, c.Exp, partitionExports) }) } } -func TestServiceExports_AddFinalizer(t *testing.T) { - serviceExports := &ServiceExports{} - serviceExports.AddFinalizer("finalizer") - require.Equal(t, []string{"finalizer"}, serviceExports.ObjectMeta.Finalizers) +func TestPartitionExports_AddFinalizer(t *testing.T) { + partitionExports := &PartitionExports{} + partitionExports.AddFinalizer("finalizer") + require.Equal(t, []string{"finalizer"}, partitionExports.ObjectMeta.Finalizers) } -func TestServiceExports_RemoveFinalizer(t *testing.T) { - serviceExports := &ServiceExports{ +func TestPartitionExports_RemoveFinalizer(t *testing.T) { + partitionExports := &PartitionExports{ ObjectMeta: metav1.ObjectMeta{ Finalizers: []string{"f1", "f2"}, }, } - serviceExports.RemoveFinalizer("f1") - require.Equal(t, []string{"f2"}, serviceExports.ObjectMeta.Finalizers) + partitionExports.RemoveFinalizer("f1") + require.Equal(t, []string{"f2"}, partitionExports.ObjectMeta.Finalizers) } -func TestServiceExports_SetSyncedCondition(t *testing.T) { - serviceExports := &ServiceExports{} - serviceExports.SetSyncedCondition(corev1.ConditionTrue, "reason", "message") +func TestPartitionExports_SetSyncedCondition(t *testing.T) { + partitionExports := &PartitionExports{} + partitionExports.SetSyncedCondition(corev1.ConditionTrue, "reason", "message") - require.Equal(t, corev1.ConditionTrue, serviceExports.Status.Conditions[0].Status) - require.Equal(t, "reason", serviceExports.Status.Conditions[0].Reason) - require.Equal(t, "message", serviceExports.Status.Conditions[0].Message) + require.Equal(t, corev1.ConditionTrue, partitionExports.Status.Conditions[0].Status) + require.Equal(t, "reason", partitionExports.Status.Conditions[0].Reason) + require.Equal(t, "message", partitionExports.Status.Conditions[0].Message) now := metav1.Now() - require.True(t, serviceExports.Status.Conditions[0].LastTransitionTime.Before(&now)) + require.True(t, partitionExports.Status.Conditions[0].LastTransitionTime.Before(&now)) } -func TestServiceExports_SetLastSyncedTime(t *testing.T) { - serviceExports := &ServiceExports{} +func TestPartitionExports_SetLastSyncedTime(t *testing.T) { + partitionExports := &PartitionExports{} syncedTime := metav1.NewTime(time.Now()) - serviceExports.SetLastSyncedTime(&syncedTime) + partitionExports.SetLastSyncedTime(&syncedTime) - require.Equal(t, &syncedTime, serviceExports.Status.LastSyncedTime) + require.Equal(t, &syncedTime, partitionExports.Status.LastSyncedTime) } -func TestServiceExports_GetSyncedConditionStatus(t *testing.T) { +func TestPartitionExports_GetSyncedConditionStatus(t *testing.T) { cases := []corev1.ConditionStatus{ corev1.ConditionUnknown, corev1.ConditionFalse, @@ -267,7 +270,7 @@ func TestServiceExports_GetSyncedConditionStatus(t *testing.T) { } for _, status := range cases { t.Run(string(status), func(t *testing.T) { - serviceExports := &ServiceExports{ + partitionExports := &PartitionExports{ Status: Status{ Conditions: []Condition{{ Type: ConditionSynced, @@ -276,57 +279,57 @@ func TestServiceExports_GetSyncedConditionStatus(t *testing.T) { }, } - require.Equal(t, status, serviceExports.SyncedConditionStatus()) + require.Equal(t, status, partitionExports.SyncedConditionStatus()) }) } } -func TestServiceExports_GetConditionWhenStatusNil(t *testing.T) { - require.Nil(t, (&ServiceExports{}).GetCondition(ConditionSynced)) +func TestPartitionExports_GetConditionWhenStatusNil(t *testing.T) { + require.Nil(t, (&PartitionExports{}).GetCondition(ConditionSynced)) } -func TestServiceExports_SyncedConditionStatusWhenStatusNil(t *testing.T) { - require.Equal(t, corev1.ConditionUnknown, (&ServiceExports{}).SyncedConditionStatus()) +func TestPartitionExports_SyncedConditionStatusWhenStatusNil(t *testing.T) { + require.Equal(t, corev1.ConditionUnknown, (&PartitionExports{}).SyncedConditionStatus()) } -func TestServiceExports_SyncedConditionWhenStatusNil(t *testing.T) { - status, reason, message := (&ServiceExports{}).SyncedCondition() +func TestPartitionExports_SyncedConditionWhenStatusNil(t *testing.T) { + status, reason, message := (&PartitionExports{}).SyncedCondition() require.Equal(t, corev1.ConditionUnknown, status) require.Equal(t, "", reason) require.Equal(t, "", message) } -func TestServiceExports_ConsulKind(t *testing.T) { - require.Equal(t, capi.ServiceExports, (&ServiceExports{}).ConsulKind()) +func TestPartitionExports_ConsulKind(t *testing.T) { + require.Equal(t, capi.PartitionExports, (&PartitionExports{}).ConsulKind()) } -func TestServiceExports_KubeKind(t *testing.T) { - require.Equal(t, "serviceexports", (&ServiceExports{}).KubeKind()) +func TestPartitionExports_KubeKind(t *testing.T) { + require.Equal(t, "partitionexports", (&PartitionExports{}).KubeKind()) } -func TestServiceExports_ConsulName(t *testing.T) { - require.Equal(t, "foo", (&ServiceExports{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}).ConsulName()) +func TestPartitionExports_ConsulName(t *testing.T) { + require.Equal(t, "foo", (&PartitionExports{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}).ConsulName()) } -func TestServiceExports_KubernetesName(t *testing.T) { - require.Equal(t, "foo", (&ServiceExports{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}).KubernetesName()) +func TestPartitionExports_KubernetesName(t *testing.T) { + require.Equal(t, "foo", (&PartitionExports{ObjectMeta: metav1.ObjectMeta{Name: "foo"}}).KubernetesName()) } -func TestServiceExports_ConsulNamespace(t *testing.T) { - require.Equal(t, common.DefaultConsulNamespace, (&ServiceExports{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "bar"}}).ConsulMirroringNS()) +func TestPartitionExports_ConsulNamespace(t *testing.T) { + require.Equal(t, common.DefaultConsulNamespace, (&PartitionExports{ObjectMeta: metav1.ObjectMeta{Name: "foo", Namespace: "bar"}}).ConsulMirroringNS()) } -func TestServiceExports_ConsulGlobalResource(t *testing.T) { - require.True(t, (&ServiceExports{}).ConsulGlobalResource()) +func TestPartitionExports_ConsulGlobalResource(t *testing.T) { + require.True(t, (&PartitionExports{}).ConsulGlobalResource()) } -func TestServiceExports_ObjectMeta(t *testing.T) { +func TestPartitionExports_ObjectMeta(t *testing.T) { meta := metav1.ObjectMeta{ Name: "name", Namespace: "namespace", } - ServiceExports := &ServiceExports{ + partitionExports := &PartitionExports{ ObjectMeta: meta, } - require.Equal(t, meta, ServiceExports.GetObjectMeta()) + require.Equal(t, meta, partitionExports.GetObjectMeta()) } diff --git a/control-plane/api/v1alpha1/serviceexports_webhook.go b/control-plane/api/v1alpha1/partitionexports_webhook.go similarity index 51% rename from control-plane/api/v1alpha1/serviceexports_webhook.go rename to control-plane/api/v1alpha1/partitionexports_webhook.go index 034ad60071..6dc2e6c2a6 100644 --- a/control-plane/api/v1alpha1/serviceexports_webhook.go +++ b/control-plane/api/v1alpha1/partitionexports_webhook.go @@ -6,7 +6,6 @@ import ( "net/http" "github.com/go-logr/logr" - "github.com/hashicorp/consul-k8s/control-plane/api/common" capi "github.com/hashicorp/consul/api" admissionv1 "k8s.io/api/admission/v1" "sigs.k8s.io/controller-runtime/pkg/client" @@ -15,13 +14,14 @@ import ( // +kubebuilder:object:generate=false -type ServiceExportsWebhook struct { +type PartitionExportsWebhook struct { client.Client ConsulClient *capi.Client Logger logr.Logger decoder *admission.Decoder EnableConsulNamespaces bool EnableNSMirroring bool + PartitionName string } // NOTE: The path value in the below line is the path to the webhook. @@ -31,40 +31,40 @@ type ServiceExportsWebhook struct { // NOTE: The below line cannot be combined with any other comment. If it is // it will break the code generation. // -// +kubebuilder:webhook:verbs=create;update,path=/mutate-v1alpha1-service-exports,mutating=true,failurePolicy=fail,groups=consul.hashicorp.com,resources=serviceexports,versions=v1alpha1,name=mutate-serviceexports.consul.hashicorp.com,sideEffects=None,admissionReviewVersions=v1beta1;v1 +// +kubebuilder:webhook:verbs=create;update,path=/mutate-v1alpha1-partitionexports,mutating=true,failurePolicy=fail,groups=consul.hashicorp.com,resources=partitionexports,versions=v1alpha1,name=mutate-partitionexports.consul.hashicorp.com,sideEffects=None,admissionReviewVersions=v1beta1;v1 -func (v *ServiceExportsWebhook) Handle(ctx context.Context, req admission.Request) admission.Response { - var serviceExports ServiceExports - var serviceExportsList ServiceExportsList - err := v.decoder.Decode(req, &serviceExports) +func (v *PartitionExportsWebhook) Handle(ctx context.Context, req admission.Request) admission.Response { + var exports PartitionExports + var exportsList PartitionExportsList + err := v.decoder.Decode(req, &exports) if err != nil { return admission.Errored(http.StatusBadRequest, err) } if req.Operation == admissionv1.Create { - v.Logger.Info("validate create", "name", serviceExports.KubernetesName()) + v.Logger.Info("validate create", "name", exports.KubernetesName()) - if serviceExports.KubernetesName() != common.Exports { + if exports.KubernetesName() != v.PartitionName { return admission.Errored(http.StatusBadRequest, - fmt.Errorf(`%s resource name must be "%s"`, - serviceExports.KubeKind(), common.Exports)) + fmt.Errorf(`%s resource name must be the same name as the partition, "%s"`, + exports.KubeKind(), v.PartitionName)) } - if err := v.Client.List(ctx, &serviceExportsList); err != nil { + if err := v.Client.List(ctx, &exportsList); err != nil { return admission.Errored(http.StatusInternalServerError, err) } - if len(serviceExportsList.Items) > 0 { + if len(exportsList.Items) > 0 { return admission.Errored(http.StatusBadRequest, - fmt.Errorf("%s resource already defined - only one serviceexports entry is supported", - serviceExports.KubeKind())) + fmt.Errorf("%s resource already defined - only one partitionexports entry is supported per Kubernetes cluster", + exports.KubeKind())) } } - return admission.Allowed(fmt.Sprintf("valid %s request", serviceExports.KubeKind())) + return admission.Allowed(fmt.Sprintf("valid %s request", exports.KubeKind())) } -func (v *ServiceExportsWebhook) InjectDecoder(d *admission.Decoder) error { +func (v *PartitionExportsWebhook) InjectDecoder(d *admission.Decoder) error { v.decoder = d return nil } diff --git a/control-plane/api/v1alpha1/serviceexports_webhook_test.go b/control-plane/api/v1alpha1/partitionexports_webhook_test.go similarity index 67% rename from control-plane/api/v1alpha1/serviceexports_webhook_test.go rename to control-plane/api/v1alpha1/partitionexports_webhook_test.go index 43bea9fd85..5ee4bc2ce6 100644 --- a/control-plane/api/v1alpha1/serviceexports_webhook_test.go +++ b/control-plane/api/v1alpha1/partitionexports_webhook_test.go @@ -6,7 +6,6 @@ import ( "testing" logrtest "github.com/go-logr/logr/testing" - "github.com/hashicorp/consul-k8s/control-plane/api/common" "github.com/stretchr/testify/require" admissionv1 "k8s.io/api/admission/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -15,36 +14,37 @@ import ( "sigs.k8s.io/controller-runtime/pkg/webhook/admission" ) -func TestValidateServiceExports(t *testing.T) { +func TestValidatePartitionExports(t *testing.T) { otherNS := "other" + otherPartition := "other" cases := map[string]struct { existingResources []runtime.Object - newResource *ServiceExports + newResource *PartitionExports expAllow bool expErrMessage string }{ "no duplicates, valid": { existingResources: nil, - newResource: &ServiceExports{ + newResource: &PartitionExports{ ObjectMeta: metav1.ObjectMeta{ - Name: common.Exports, + Name: otherPartition, }, - Spec: ServiceExportsSpec{}, + Spec: PartitionExportsSpec{}, }, expAllow: true, }, - "serviceexports exists": { - existingResources: []runtime.Object{&ServiceExports{ + "partitionexports exists": { + existingResources: []runtime.Object{&PartitionExports{ ObjectMeta: metav1.ObjectMeta{ - Name: common.Exports, + Name: otherPartition, }, }}, - newResource: &ServiceExports{ + newResource: &PartitionExports{ ObjectMeta: metav1.ObjectMeta{ - Name: common.Exports, + Name: otherPartition, }, - Spec: ServiceExportsSpec{ + Spec: PartitionExportsSpec{ Services: []ExportedService{ { Name: "service", @@ -55,17 +55,17 @@ func TestValidateServiceExports(t *testing.T) { }, }, expAllow: false, - expErrMessage: "serviceexports resource already defined - only one serviceexports entry is supported", + expErrMessage: "partitionexports resource already defined - only one partitionexports entry is supported per Kubernetes cluster", }, "name not exports": { existingResources: []runtime.Object{}, - newResource: &ServiceExports{ + newResource: &PartitionExports{ ObjectMeta: metav1.ObjectMeta{ Name: "local", }, }, expAllow: false, - expErrMessage: "serviceexports resource name must be \"exports\"", + expErrMessage: "partitionexports resource name must be the same name as the partition, \"other\"", }, } for name, c := range cases { @@ -74,16 +74,17 @@ func TestValidateServiceExports(t *testing.T) { marshalledRequestObject, err := json.Marshal(c.newResource) require.NoError(t, err) s := runtime.NewScheme() - s.AddKnownTypes(GroupVersion, &ServiceExports{}, &ServiceExportsList{}) + s.AddKnownTypes(GroupVersion, &PartitionExports{}, &PartitionExportsList{}) client := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(c.existingResources...).Build() decoder, err := admission.NewDecoder(s) require.NoError(t, err) - validator := &ServiceExportsWebhook{ - Client: client, - ConsulClient: nil, - Logger: logrtest.TestLogger{T: t}, - decoder: decoder, + validator := &PartitionExportsWebhook{ + Client: client, + ConsulClient: nil, + Logger: logrtest.TestLogger{T: t}, + PartitionName: otherPartition, + decoder: decoder, } response := validator.Handle(ctx, admission.Request{ AdmissionRequest: admissionv1.AdmissionRequest{ diff --git a/control-plane/api/v1alpha1/zz_generated.deepcopy.go b/control-plane/api/v1alpha1/zz_generated.deepcopy.go index 7e66af3e7a..04288255f1 100644 --- a/control-plane/api/v1alpha1/zz_generated.deepcopy.go +++ b/control-plane/api/v1alpha1/zz_generated.deepcopy.go @@ -547,6 +547,87 @@ func (in *MeshSpec) DeepCopy() *MeshSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PartitionExports) DeepCopyInto(out *PartitionExports) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PartitionExports. +func (in *PartitionExports) DeepCopy() *PartitionExports { + if in == nil { + return nil + } + out := new(PartitionExports) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *PartitionExports) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PartitionExportsList) DeepCopyInto(out *PartitionExportsList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]PartitionExports, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PartitionExportsList. +func (in *PartitionExportsList) DeepCopy() *PartitionExportsList { + if in == nil { + return nil + } + out := new(PartitionExportsList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *PartitionExportsList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PartitionExportsSpec) DeepCopyInto(out *PartitionExportsSpec) { + *out = *in + if in.Services != nil { + in, out := &in.Services, &out.Services + *out = make([]ExportedService, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PartitionExportsSpec. +func (in *PartitionExportsSpec) DeepCopy() *PartitionExportsSpec { + if in == nil { + return nil + } + out := new(PartitionExportsSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PassiveHealthCheck) DeepCopyInto(out *PassiveHealthCheck) { *out = *in @@ -775,87 +856,6 @@ func (in *ServiceDefaultsSpec) DeepCopy() *ServiceDefaultsSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ServiceExports) DeepCopyInto(out *ServiceExports) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceExports. -func (in *ServiceExports) DeepCopy() *ServiceExports { - if in == nil { - return nil - } - out := new(ServiceExports) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ServiceExports) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ServiceExportsList) DeepCopyInto(out *ServiceExportsList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]ServiceExports, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceExportsList. -func (in *ServiceExportsList) DeepCopy() *ServiceExportsList { - if in == nil { - return nil - } - out := new(ServiceExportsList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ServiceExportsList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ServiceExportsSpec) DeepCopyInto(out *ServiceExportsSpec) { - *out = *in - if in.Services != nil { - in, out := &in.Services, &out.Services - *out = make([]ExportedService, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServiceExportsSpec. -func (in *ServiceExportsSpec) DeepCopy() *ServiceExportsSpec { - if in == nil { - return nil - } - out := new(ServiceExportsSpec) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ServiceIntentions) DeepCopyInto(out *ServiceIntentions) { *out = *in diff --git a/control-plane/config/crd/bases/consul.hashicorp.com_serviceexports.yaml b/control-plane/config/crd/bases/consul.hashicorp.com_partitionexports.yaml similarity index 93% rename from control-plane/config/crd/bases/consul.hashicorp.com_serviceexports.yaml rename to control-plane/config/crd/bases/consul.hashicorp.com_partitionexports.yaml index c4648703dc..8e31c6ade8 100644 --- a/control-plane/config/crd/bases/consul.hashicorp.com_serviceexports.yaml +++ b/control-plane/config/crd/bases/consul.hashicorp.com_partitionexports.yaml @@ -6,14 +6,14 @@ metadata: annotations: controller-gen.kubebuilder.io/version: v0.6.0 creationTimestamp: null - name: serviceexports.consul.hashicorp.com + name: partitionexports.consul.hashicorp.com spec: group: consul.hashicorp.com names: - kind: ServiceExports - listKind: ServiceExportsList - plural: serviceexports - singular: serviceexports + kind: PartitionExports + listKind: PartitionExportsList + plural: partitionexports + singular: partitionexports scope: Namespaced versions: - additionalPrinterColumns: @@ -32,7 +32,7 @@ spec: name: v1alpha1 schema: openAPIV3Schema: - description: ServiceExports is the Schema for the serviceexports API + description: PartitionExports is the Schema for the partitionexports API properties: apiVersion: description: 'APIVersion defines the versioned schema of this representation @@ -47,7 +47,7 @@ spec: metadata: type: object spec: - description: ServiceExportsSpec defines the desired state of ServiceExports + description: PartitionExportsSpec defines the desired state of PartitionExports properties: services: description: Services is a list of services to be exported and the diff --git a/control-plane/config/crd/kustomization.yaml b/control-plane/config/crd/kustomization.yaml index db5ee4e575..1c9666aac6 100644 --- a/control-plane/config/crd/kustomization.yaml +++ b/control-plane/config/crd/kustomization.yaml @@ -10,7 +10,7 @@ resources: - bases/consul.hashicorp.com_ingressgateways.yaml - bases/consul.hashicorp.com_terminatinggateways.yaml - bases/consul.hashicorp.com_meshes.yaml -- bases/consul.hashicorp.com_serviceexports.yaml +- bases/consul.hashicorp.com_partitionexports.yaml # +kubebuilder:scaffold:crdkustomizeresource patchesStrategicMerge: @@ -24,7 +24,7 @@ patchesStrategicMerge: - patches/webhook_in_ingressgateways.yaml - patches/webhook_in_terminatinggateways.yaml #- patches/webhook_in_meshes.yaml -#- patches/webhook_in_serviceexports.yaml +#- patches/webhook_in_partitionexports.yaml # +kubebuilder:scaffold:crdkustomizewebhookpatch # [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix. @@ -37,7 +37,7 @@ patchesStrategicMerge: #- patches/cainjection_in_ingressgateways.yaml #- patches/cainjection_in_terminatinggateways.yaml #- patches/cainjection_in_meshes.yaml -#- patches/cainjection_in_serviceexports.yaml +#- patches/cainjection_in_partitionexports.yaml # +kubebuilder:scaffold:crdkustomizecainjectionpatch # the following config is for teaching kustomize how to do kustomization for CRDs. diff --git a/control-plane/config/crd/patches/cainjection_in_serviceexports.yaml b/control-plane/config/crd/patches/cainjection_in_serviceexports.yaml deleted file mode 100644 index ecf0240c53..0000000000 --- a/control-plane/config/crd/patches/cainjection_in_serviceexports.yaml +++ /dev/null @@ -1,8 +0,0 @@ -# The following patch adds a directive for certmanager to inject CA into the CRD -# CRD conversion requires k8s 1.13 or later. -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - annotations: - cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME) - name: serviceexports.consul.hashicorp.com diff --git a/control-plane/config/crd/patches/webhook_in_serviceexports.yaml b/control-plane/config/crd/patches/webhook_in_partitionexports.yaml similarity index 92% rename from control-plane/config/crd/patches/webhook_in_serviceexports.yaml rename to control-plane/config/crd/patches/webhook_in_partitionexports.yaml index 9f4fc7a30f..3084d0409c 100644 --- a/control-plane/config/crd/patches/webhook_in_serviceexports.yaml +++ b/control-plane/config/crd/patches/webhook_in_partitionexports.yaml @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: - name: serviceexports.consul.hashicorp.com + name: partitionexports.consul.hashicorp.com spec: conversion: strategy: Webhook diff --git a/control-plane/config/rbac/serviceexport_editor_role.yaml b/control-plane/config/rbac/partitionexport_editor_role.yaml similarity index 66% rename from control-plane/config/rbac/serviceexport_editor_role.yaml rename to control-plane/config/rbac/partitionexport_editor_role.yaml index 9e0ba97a12..45b9d4c5c0 100644 --- a/control-plane/config/rbac/serviceexport_editor_role.yaml +++ b/control-plane/config/rbac/partitionexport_editor_role.yaml @@ -1,13 +1,13 @@ -# permissions for end users to edit serviceexports. +# permissions for end users to edit partitionexports. apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: - name: serviceexport-editor-role + name: partitionexport-editor-role rules: - apiGroups: - consul.hashicorp.com resources: - - serviceexports + - partitionexports verbs: - create - delete @@ -19,6 +19,6 @@ rules: - apiGroups: - consul.hashicorp.com resources: - - serviceexports/status + - partitionexports/status verbs: - get diff --git a/control-plane/config/rbac/serviceexport_viewer_role.yaml b/control-plane/config/rbac/partitionexport_viewer_role.yaml similarity index 62% rename from control-plane/config/rbac/serviceexport_viewer_role.yaml rename to control-plane/config/rbac/partitionexport_viewer_role.yaml index a0da087cf8..ce62786b98 100644 --- a/control-plane/config/rbac/serviceexport_viewer_role.yaml +++ b/control-plane/config/rbac/partitionexport_viewer_role.yaml @@ -1,13 +1,13 @@ -# permissions for end users to view serviceexports. +# permissions for end users to view partitionexports. apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: - name: serviceexport-viewer-role + name: partitionexport-viewer-role rules: - apiGroups: - consul.hashicorp.com resources: - - serviceexports + - partitionexports verbs: - get - list @@ -15,6 +15,6 @@ rules: - apiGroups: - consul.hashicorp.com resources: - - serviceexports/status + - partitionexports/status verbs: - get diff --git a/control-plane/config/rbac/role.yaml b/control-plane/config/rbac/role.yaml index 9daf012e58..f1a46e72d3 100644 --- a/control-plane/config/rbac/role.yaml +++ b/control-plane/config/rbac/role.yaml @@ -49,7 +49,7 @@ rules: - apiGroups: - consul.hashicorp.com resources: - - proxydefaults + - partitionexports verbs: - create - delete @@ -61,7 +61,7 @@ rules: - apiGroups: - consul.hashicorp.com resources: - - proxydefaults/status + - partitionexports/status verbs: - get - patch @@ -69,7 +69,7 @@ rules: - apiGroups: - consul.hashicorp.com resources: - - servicedefaults + - proxydefaults verbs: - create - delete @@ -81,7 +81,7 @@ rules: - apiGroups: - consul.hashicorp.com resources: - - servicedefaults/status + - proxydefaults/status verbs: - get - patch @@ -89,7 +89,7 @@ rules: - apiGroups: - consul.hashicorp.com resources: - - serviceexports + - servicedefaults verbs: - create - delete @@ -101,7 +101,7 @@ rules: - apiGroups: - consul.hashicorp.com resources: - - serviceexports/status + - servicedefaults/status verbs: - get - patch diff --git a/control-plane/config/samples/consul_v1alpha1_serviceexport.yaml b/control-plane/config/samples/consul_v1alpha1_partitionexport.yaml similarity index 64% rename from control-plane/config/samples/consul_v1alpha1_serviceexport.yaml rename to control-plane/config/samples/consul_v1alpha1_partitionexport.yaml index f1d5414d71..fa34ecf043 100644 --- a/control-plane/config/samples/consul_v1alpha1_serviceexport.yaml +++ b/control-plane/config/samples/consul_v1alpha1_partitionexport.yaml @@ -1,7 +1,7 @@ apiVersion: consul.hashicorp.com/v1alpha1 -kind: ServiceExport +kind: PartitionExport metadata: - name: serviceexport-sample + name: exports spec: # Add fields here foo: bar diff --git a/control-plane/config/webhook/manifests.yaml b/control-plane/config/webhook/manifests.yaml index b2159537d5..8264b31887 100644 --- a/control-plane/config/webhook/manifests.yaml +++ b/control-plane/config/webhook/manifests.yaml @@ -55,9 +55,9 @@ webhooks: service: name: webhook-service namespace: system - path: /mutate-v1alpha1-proxydefaults + path: /mutate-v1alpha1-partitionexports failurePolicy: Fail - name: mutate-proxydefaults.consul.hashicorp.com + name: mutate-partitionexports.consul.hashicorp.com rules: - apiGroups: - consul.hashicorp.com @@ -67,7 +67,7 @@ webhooks: - CREATE - UPDATE resources: - - proxydefaults + - partitionexports sideEffects: None - admissionReviewVersions: - v1beta1 @@ -76,9 +76,9 @@ webhooks: service: name: webhook-service namespace: system - path: /mutate-v1alpha1-servicedefaults + path: /mutate-v1alpha1-proxydefaults failurePolicy: Fail - name: mutate-servicedefaults.consul.hashicorp.com + name: mutate-proxydefaults.consul.hashicorp.com rules: - apiGroups: - consul.hashicorp.com @@ -88,7 +88,7 @@ webhooks: - CREATE - UPDATE resources: - - servicedefaults + - proxydefaults sideEffects: None - admissionReviewVersions: - v1beta1 @@ -97,9 +97,9 @@ webhooks: service: name: webhook-service namespace: system - path: /mutate-v1alpha1-service-exports + path: /mutate-v1alpha1-servicedefaults failurePolicy: Fail - name: mutate-mesh.consul.hashicorp.com + name: mutate-servicedefaults.consul.hashicorp.com rules: - apiGroups: - consul.hashicorp.com @@ -109,7 +109,7 @@ webhooks: - CREATE - UPDATE resources: - - mesh + - servicedefaults sideEffects: None - admissionReviewVersions: - v1beta1 diff --git a/control-plane/controller/partitionexports_controller.go b/control-plane/controller/partitionexports_controller.go new file mode 100644 index 0000000000..fd1034a81b --- /dev/null +++ b/control-plane/controller/partitionexports_controller.go @@ -0,0 +1,40 @@ +package controller + +import ( + "context" + + "github.com/go-logr/logr" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/types" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" + + consulv1alpha1 "github.com/hashicorp/consul-k8s/control-plane/api/v1alpha1" +) + +// PartitionExportsController reconciles a PartitionExports object +type PartitionExportsController struct { + client.Client + Log logr.Logger + Scheme *runtime.Scheme + ConfigEntryController *ConfigEntryController +} + +// +kubebuilder:rbac:groups=consul.hashicorp.com,resources=partitionexports,verbs=get;list;watch;create;update;patch;delete +// +kubebuilder:rbac:groups=consul.hashicorp.com,resources=partitionexports/status,verbs=get;update;patch + +func (r *PartitionExportsController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { + return r.ConfigEntryController.ReconcileEntry(ctx, r, req, &consulv1alpha1.PartitionExports{}) +} + +func (r *PartitionExportsController) Logger(name types.NamespacedName) logr.Logger { + return r.Log.WithValues("request", name) +} + +func (r *PartitionExportsController) UpdateStatus(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error { + return r.Status().Update(ctx, obj, opts...) +} + +func (r *PartitionExportsController) SetupWithManager(mgr ctrl.Manager) error { + return setupWithManager(mgr, &consulv1alpha1.PartitionExports{}, r) +} diff --git a/control-plane/controller/serviceexports_controller.go b/control-plane/controller/serviceexports_controller.go deleted file mode 100644 index f18215d5b7..0000000000 --- a/control-plane/controller/serviceexports_controller.go +++ /dev/null @@ -1,40 +0,0 @@ -package controller - -import ( - "context" - - "github.com/go-logr/logr" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/client" - - consulv1alpha1 "github.com/hashicorp/consul-k8s/control-plane/api/v1alpha1" -) - -// ServiceExportsController reconciles a ServiceExports object -type ServiceExportsController struct { - client.Client - Log logr.Logger - Scheme *runtime.Scheme - ConfigEntryController *ConfigEntryController -} - -// +kubebuilder:rbac:groups=consul.hashicorp.com,resources=serviceexports,verbs=get;list;watch;create;update;patch;delete -// +kubebuilder:rbac:groups=consul.hashicorp.com,resources=serviceexports/status,verbs=get;update;patch - -func (r *ServiceExportsController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - return r.ConfigEntryController.ReconcileEntry(ctx, r, req, &consulv1alpha1.ServiceExports{}) -} - -func (r *ServiceExportsController) Logger(name types.NamespacedName) logr.Logger { - return r.Log.WithValues("request", name) -} - -func (r *ServiceExportsController) UpdateStatus(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error { - return r.Status().Update(ctx, obj, opts...) -} - -func (r *ServiceExportsController) SetupWithManager(mgr ctrl.Manager) error { - return setupWithManager(mgr, &consulv1alpha1.ServiceExports{}, r) -} diff --git a/control-plane/go.mod b/control-plane/go.mod index 39e734f11d..044d9f347c 100644 --- a/control-plane/go.mod +++ b/control-plane/go.mod @@ -10,7 +10,7 @@ require ( github.com/google/go-cmp v0.5.6 github.com/google/go-querystring v1.0.0 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 - github.com/hashicorp/consul/api v1.10.1-0.20211020192418-04cd2c983e9c + github.com/hashicorp/consul/api v1.10.1-0.20211025235848-5c24ed61a89c github.com/hashicorp/consul/sdk v0.8.0 github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-discover v0.0.0-20200812215701-c4b85f6ed31f diff --git a/control-plane/go.sum b/control-plane/go.sum index 860c239912..e80510e6c9 100644 --- a/control-plane/go.sum +++ b/control-plane/go.sum @@ -297,8 +297,8 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= -github.com/hashicorp/consul/api v1.10.1-0.20211020192418-04cd2c983e9c h1:7eKUSC17HDH0+lHsI/fiPe5y8hMarXJdECqG7KiGkNA= -github.com/hashicorp/consul/api v1.10.1-0.20211020192418-04cd2c983e9c/go.mod h1:XjsvQN+RJGWI2TWy1/kqaE16HrR2J/FWgkYjdZQsX9M= +github.com/hashicorp/consul/api v1.10.1-0.20211025235848-5c24ed61a89c h1:7hQzN7YHI2XscCNqPVW5pORQSwJWdFgObnwXNFdEJI8= +github.com/hashicorp/consul/api v1.10.1-0.20211025235848-5c24ed61a89c/go.mod h1:XjsvQN+RJGWI2TWy1/kqaE16HrR2J/FWgkYjdZQsX9M= github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= github.com/hashicorp/consul/sdk v0.8.0 h1:OJtKBtEjboEZvG6AOUdh4Z1Zbyu0WcxQ0qatRrZHTVU= github.com/hashicorp/consul/sdk v0.8.0/go.mod h1:GBvyrGALthsZObzUGsfgHZQDXjg4lOjagTIwIR1vPms= diff --git a/control-plane/subcommand/controller/command.go b/control-plane/subcommand/controller/command.go index 96a218f185..e1640de4c8 100644 --- a/control-plane/subcommand/controller/command.go +++ b/control-plane/subcommand/controller/command.go @@ -183,13 +183,13 @@ func (c *Command) Run(args []string) int { setupLog.Error(err, "unable to create controller", "controller", common.Mesh) return 1 } - if err = (&controller.ServiceExportsController{ + if err = (&controller.PartitionExportsController{ ConfigEntryController: configEntryReconciler, Client: mgr.GetClient(), - Log: ctrl.Log.WithName("controller").WithName(common.ServiceExports), + Log: ctrl.Log.WithName("controller").WithName(common.PartitionExports), Scheme: mgr.GetScheme(), }).SetupWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create controller", "controller", common.ServiceExports) + setupLog.Error(err, "unable to create controller", "controller", common.PartitionExports) return 1 } if err = (&controller.ServiceRouterController{ @@ -281,13 +281,14 @@ func (c *Command) Run(args []string) int { EnableConsulNamespaces: c.flagEnableNamespaces, EnableNSMirroring: c.flagEnableNSMirroring, }}) - mgr.GetWebhookServer().Register("/mutate-v1alpha1-serviceexports", - &webhook.Admission{Handler: &v1alpha1.ServiceExportsWebhook{ + mgr.GetWebhookServer().Register("/mutate-v1alpha1-partitionexports", + &webhook.Admission{Handler: &v1alpha1.PartitionExportsWebhook{ Client: mgr.GetClient(), ConsulClient: consulClient, - Logger: ctrl.Log.WithName("webhooks").WithName(common.ServiceExports), + Logger: ctrl.Log.WithName("webhooks").WithName(common.PartitionExports), EnableConsulNamespaces: c.flagEnableNamespaces, EnableNSMirroring: c.flagEnableNSMirroring, + PartitionName: c.httpFlags.Partition(), }}) mgr.GetWebhookServer().Register("/mutate-v1alpha1-servicerouter", &webhook.Admission{Handler: &v1alpha1.ServiceRouterWebhook{