Skip to content

Commit

Permalink
Rename GatewayClassController to prevent name collision
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Eckert committed Jun 8, 2023
1 parent 097f945 commit 32fe71e
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion acceptance/tests/api-gateway/api_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

const (
StaticClientName = "static-client"
gatewayClassControllerName = "hashicorp.com/consul-api-gateway-controller"
gatewayClassControllerName = "hashicorp.com/consul-gatewayclass-controller"
gatewayClassFinalizer = "gateway-exists-finalizer.consul.hashicorp.com"
gatewayFinalizer = "gateway-finalizer.consul.hashicorp.com"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ kind: GatewayClass
metadata:
name: gateway-class
spec:
controllerName: "hashicorp.com/consul-api-gateway-controller"
controllerName: "consul.hashicorp.com/gatewayclass-controller"
parametersRef:
group: consul.hashicorp.com
kind: GatewayClassConfig
Expand Down
2 changes: 1 addition & 1 deletion charts/consul/templates/api-gateway-gatewayclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ metadata:
release: {{ .Release.Name }}
component: api-gateway-controller
spec:
controllerName: hashicorp.com/consul-api-gateway-controller
controllerName: consul.hashicorp.com/gatewayclass-controller
parametersRef:
group: api-gateway.consul.hashicorp.com
kind: GatewayClassConfig
Expand Down
2 changes: 1 addition & 1 deletion charts/consul/templates/gateway-resources-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ spec:
- gateway-resources
- -gateway-class-name=consul-api-gateway
- -gateway-class-config-name=consul-api-gateway
- -controller-name=hashicorp.com/consul-api-gateway-controller
- -controller-name=consul.hashicorp.com/gatewayclass-controller
- -app={{template "consul.name" .}}
- -chart={{template "consul.chart" .}}
- -heritage={{ .Release.Service }}
Expand Down
2 changes: 2 additions & 0 deletions control-plane/api-gateway/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
package common

const (
GatewayClassControllerName = "consul.hashicorp.com/gatewayclass-controller"

AnnotationGatewayClassConfig = "consul.hashicorp.com/gateway-class-config"
)
14 changes: 8 additions & 6 deletions control-plane/api-gateway/controllers/gateway_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ type GatewayControllerConfig struct {
// GatewayController reconciles a Gateway object.
// The Gateway is responsible for defining the behavior of API gateways.
type GatewayController struct {
HelmConfig common.HelmConfig
Log logr.Logger
Translator common.ResourceTranslator
Name string
HelmConfig common.HelmConfig
Log logr.Logger
Translator common.ResourceTranslator

cache *cache.Cache
gatewayCache *cache.GatewayCache
allowK8sNamespacesSet mapset.Set
Expand Down Expand Up @@ -173,7 +175,7 @@ func (r *GatewayController) Reconcile(ctx context.Context, req ctrl.Request) (ct
binder := binding.NewBinder(binding.BinderConfig{
Logger: log,
Translator: r.Translator,
ControllerName: GatewayClassControllerName,
ControllerName: common.GatewayClassControllerName,
Namespaces: namespaces,
GatewayClassConfig: gatewayClassConfig,
GatewayClass: gatewayClass,
Expand Down Expand Up @@ -755,7 +757,7 @@ func (c *GatewayController) getConfigForGatewayClass(ctx context.Context, gatewa
if ref := gatewayClassConfig.Spec.ParametersRef; ref != nil {
if string(ref.Group) != v1alpha1.GroupVersion.Group ||
ref.Kind != v1alpha1.GatewayClassConfigKind ||
gatewayClassConfig.Spec.ControllerName != GatewayClassControllerName {
string(gatewayClassConfig.Spec.ControllerName) != c.Name {
// we don't have supported params, so return nil
return nil, nil
}
Expand All @@ -782,7 +784,7 @@ func (c *GatewayController) fetchControlledGateways(ctx context.Context, resourc

list := gwv1beta1.GatewayClassList{}
if err := c.Client.List(ctx, &list, &client.ListOptions{
FieldSelector: fields.OneTermEqualSelector(GatewayClass_ControllerNameIndex, GatewayClassControllerName),
FieldSelector: fields.OneTermEqualSelector(GatewayClass_ControllerNameIndex, c.Name),
}); err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
)

const (
GatewayClassControllerName = "hashicorp.com/consul-api-gateway-controller"

gatewayClassFinalizer = "gateway-exists-finalizer.consul.hashicorp.com"

// GatewayClass status fields.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"sigs.k8s.io/gateway-api/apis/v1beta1"
gwv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"

"github.com/hashicorp/consul-k8s/control-plane/api-gateway/common"
"github.com/hashicorp/consul-k8s/control-plane/api/v1alpha1"
)

Expand Down Expand Up @@ -57,7 +58,7 @@ func TestGatewayClassReconciler(t *testing.T) {
Finalizers: []string{gatewayClassFinalizer},
},
Spec: gwv1beta1.GatewayClassSpec{
ControllerName: GatewayClassControllerName,
ControllerName: common.GatewayClassControllerName,
},
},
expectedResult: ctrl.Result{},
Expand All @@ -81,7 +82,7 @@ func TestGatewayClassReconciler(t *testing.T) {
Finalizers: []string{},
},
Spec: gwv1beta1.GatewayClassSpec{
ControllerName: GatewayClassControllerName,
ControllerName: common.GatewayClassControllerName,
},
},
expectedResult: ctrl.Result{},
Expand Down Expand Up @@ -127,7 +128,7 @@ func TestGatewayClassReconciler(t *testing.T) {
Finalizers: []string{gatewayClassFinalizer},
},
Spec: gwv1beta1.GatewayClassSpec{
ControllerName: GatewayClassControllerName,
ControllerName: common.GatewayClassControllerName,
ParametersRef: &gwv1beta1.ParametersReference{
Kind: "some-nonsense",
},
Expand All @@ -153,7 +154,7 @@ func TestGatewayClassReconciler(t *testing.T) {
Finalizers: []string{gatewayClassFinalizer},
},
Spec: gwv1beta1.GatewayClassSpec{
ControllerName: GatewayClassControllerName,
ControllerName: common.GatewayClassControllerName,
ParametersRef: &gwv1beta1.ParametersReference{
Kind: v1alpha1.GatewayClassConfigKind,
Name: "does-not-exist",
Expand Down Expand Up @@ -189,7 +190,7 @@ func TestGatewayClassReconciler(t *testing.T) {
DeletionTimestamp: &deletionTimestamp,
},
Spec: gwv1beta1.GatewayClassSpec{
ControllerName: GatewayClassControllerName,
ControllerName: common.GatewayClassControllerName,
},
},
expectedResult: ctrl.Result{},
Expand All @@ -208,7 +209,7 @@ func TestGatewayClassReconciler(t *testing.T) {
DeletionTimestamp: &deletionTimestamp,
},
Spec: gwv1beta1.GatewayClassSpec{
ControllerName: GatewayClassControllerName,
ControllerName: common.GatewayClassControllerName,
},
},
k8sObjects: []runtime.Object{
Expand Down Expand Up @@ -246,7 +247,7 @@ func TestGatewayClassReconciler(t *testing.T) {

r := &GatewayClassController{
Client: fakeClient,
ControllerName: GatewayClassControllerName,
ControllerName: common.GatewayClassControllerName,
Log: logrtest.New(t),
}
result, err := r.Reconcile(context.Background(), req)
Expand Down
2 changes: 1 addition & 1 deletion control-plane/subcommand/inject-connect/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ func (c *Command) Run(args []string) int {
}

if err := (&gatewaycontrollers.GatewayClassController{
ControllerName: gatewaycontrollers.GatewayClassControllerName,
ControllerName: gatewaycommon.GatewayClassControllerName,
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("GatewayClass"),
}).SetupWithManager(ctx, mgr); err != nil {
Expand Down

0 comments on commit 32fe71e

Please sign in to comment.