Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NET-6722 Rename MeshConfigController to ConsulResourceController #3283

Merged
merged 15 commits into from
Nov 30, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type TrafficPermissionsWebhook struct {
client.Client
}

var _ common.MeshConfigLister = &TrafficPermissionsWebhook{}
var _ common.ConsulResourceLister = &TrafficPermissionsWebhook{}

// NOTE: The path value in the below line is the path to the webhook.
// If it is updated, run code-gen, update subcommand/inject-connect/command.go
Expand All @@ -47,14 +47,14 @@ func (v *TrafficPermissionsWebhook) Handle(ctx context.Context, req admission.Re
return common.ValidateMeshConfig(ctx, req, v.Logger, v, &resource, v.ConsulTenancyConfig)
}

func (v *TrafficPermissionsWebhook) List(ctx context.Context) ([]common.MeshConfig, error) {
func (v *TrafficPermissionsWebhook) List(ctx context.Context) ([]common.ConsulResource, error) {
var resourceList TrafficPermissionsList
if err := v.Client.List(ctx, &resourceList); err != nil {
return nil, err
}
var entries []common.MeshConfig
var entries []common.ConsulResource
for _, item := range resourceList.Items {
entries = append(entries, common.MeshConfig(item))
entries = append(entries, common.ConsulResource(item))
}
return entries, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"
)

type MeshConfig interface {
type ConsulResource interface {
ResourceID(namespace, partition string) *pbresource.ID
Resource(namespace, partition string) *pbresource.Resource

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import (
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// MeshConfigLister is implemented by CRD-specific webhooks.
type MeshConfigLister interface {
// ConsulResourceLister is implemented by CRD-specific webhooks.
type ConsulResourceLister interface {
// List returns all resources of this type across all namespaces in a
// Kubernetes cluster.
List(ctx context.Context) ([]MeshConfig, error)
List(ctx context.Context) ([]ConsulResource, error)
}

// ValidateMeshConfig validates a MeshConfig. It is a generic method that
Expand All @@ -30,8 +30,8 @@ func ValidateMeshConfig(
ctx context.Context,
req admission.Request,
logger logr.Logger,
meshConfigLister MeshConfigLister,
meshConfig MeshConfig,
meshConfigLister ConsulResourceLister,
meshConfig ConsulResource,
tenancy ConsulTenancyConfig) admission.Response {

defaultingPatches, err := MeshConfigDefaultingPatches(meshConfig, tenancy)
Expand Down Expand Up @@ -68,7 +68,7 @@ func ValidateMeshConfig(
}

// MeshConfigDefaultingPatches returns the patches needed to set fields to their defaults.
func MeshConfigDefaultingPatches(meshConfig MeshConfig, tenancy ConsulTenancyConfig) ([]jsonpatch.Operation, error) {
func MeshConfigDefaultingPatches(meshConfig ConsulResource, tenancy ConsulTenancyConfig) ([]jsonpatch.Operation, error) {
beforeDefaulting, err := json.Marshal(meshConfig)
if err != nil {
return nil, fmt.Errorf("marshalling input: %s", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func TestValidateMeshConfig(t *testing.T) {
otherNS := "other"

cases := map[string]struct {
existingResources []MeshConfig
newResource MeshConfig
existingResources []ConsulResource
newResource ConsulResource
enableNamespaces bool
nsMirroring bool
consulDestinationNS string
Expand Down Expand Up @@ -55,7 +55,7 @@ func TestValidateMeshConfig(t *testing.T) {
expErrMessage: "invalid",
},
"duplicate name": {
existingResources: []MeshConfig{&mockMeshConfig{
existingResources: []ConsulResource{&mockMeshConfig{
t-eckert marked this conversation as resolved.
Show resolved Hide resolved
MockName: "foo",
MockNamespace: "default",
}},
Expand All @@ -68,7 +68,7 @@ func TestValidateMeshConfig(t *testing.T) {
expErrMessage: "mockkind resource with name \"foo\" is already defined – all mockkind resources must have unique names across namespaces",
},
"duplicate name, namespaces enabled": {
existingResources: []MeshConfig{&mockMeshConfig{
existingResources: []ConsulResource{&mockMeshConfig{
MockName: "foo",
MockNamespace: "default",
}},
Expand All @@ -82,7 +82,7 @@ func TestValidateMeshConfig(t *testing.T) {
expErrMessage: "mockkind resource with name \"foo\" is already defined – all mockkind resources must have unique names across namespaces",
},
"duplicate name, namespaces enabled, mirroring enabled": {
existingResources: []MeshConfig{&mockMeshConfig{
existingResources: []ConsulResource{&mockMeshConfig{
MockName: "foo",
MockNamespace: "default",
}},
Expand Down Expand Up @@ -152,12 +152,12 @@ func TestMeshConfigDefaultingPatches(t *testing.T) {
}

type mockMeshConfigLister struct {
Resources []MeshConfig
Resources []ConsulResource
}

var _ MeshConfigLister = &mockMeshConfigLister{}
var _ ConsulResourceLister = &mockMeshConfigLister{}

func (in *mockMeshConfigLister) List(_ context.Context) ([]MeshConfig, error) {
func (in *mockMeshConfigLister) List(_ context.Context) ([]ConsulResource, error) {
return in.Resources, nil
}

Expand All @@ -167,7 +167,7 @@ type mockMeshConfig struct {
Valid bool
}

var _ MeshConfig = &mockMeshConfig{}
var _ ConsulResource = &mockMeshConfig{}

func (in *mockMeshConfig) ResourceID(_, _ string) *pbresource.ID {
return nil
Expand Down
8 changes: 4 additions & 4 deletions control-plane/api/mesh/v2beta1/grpc_route_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type GRPCRouteWebhook struct {
client.Client
}

var _ common.MeshConfigLister = &GRPCRouteWebhook{}
var _ common.ConsulResourceLister = &GRPCRouteWebhook{}

// NOTE: The path value in the below line is the path to the webhook.
// If it is updated, run code-gen, update subcommand/inject-connect/command.go
Expand All @@ -47,14 +47,14 @@ func (v *GRPCRouteWebhook) Handle(ctx context.Context, req admission.Request) ad
return common.ValidateMeshConfig(ctx, req, v.Logger, v, &resource, v.ConsulTenancyConfig)
}

func (v *GRPCRouteWebhook) List(ctx context.Context) ([]common.MeshConfig, error) {
func (v *GRPCRouteWebhook) List(ctx context.Context) ([]common.ConsulResource, error) {
var resourceList GRPCRouteList
if err := v.Client.List(ctx, &resourceList); err != nil {
return nil, err
}
var entries []common.MeshConfig
var entries []common.ConsulResource
for _, item := range resourceList.Items {
entries = append(entries, common.MeshConfig(item))
entries = append(entries, common.ConsulResource(item))
}
return entries, nil
}
Expand Down
8 changes: 4 additions & 4 deletions control-plane/api/mesh/v2beta1/http_route_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type HTTPRouteWebhook struct {
client.Client
}

var _ common.MeshConfigLister = &HTTPRouteWebhook{}
var _ common.ConsulResourceLister = &HTTPRouteWebhook{}

// NOTE: The path value in the below line is the path to the webhook.
// If it is updated, run code-gen, update subcommand/inject-connect/command.go
Expand All @@ -47,14 +47,14 @@ func (v *HTTPRouteWebhook) Handle(ctx context.Context, req admission.Request) ad
return common.ValidateMeshConfig(ctx, req, v.Logger, v, &resource, v.ConsulTenancyConfig)
}

func (v *HTTPRouteWebhook) List(ctx context.Context) ([]common.MeshConfig, error) {
func (v *HTTPRouteWebhook) List(ctx context.Context) ([]common.ConsulResource, error) {
var resourceList HTTPRouteList
if err := v.Client.List(ctx, &resourceList); err != nil {
return nil, err
}
var entries []common.MeshConfig
var entries []common.ConsulResource
for _, item := range resourceList.Items {
entries = append(entries, common.MeshConfig(item))
entries = append(entries, common.ConsulResource(item))
}
return entries, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type ProxyConfigurationWebhook struct {
client.Client
}

var _ common.MeshConfigLister = &ProxyConfigurationWebhook{}
var _ common.ConsulResourceLister = &ProxyConfigurationWebhook{}

// NOTE: The path value in the below line is the path to the webhook.
// If it is updated, run code-gen, update subcommand/inject-connect/command.go
Expand All @@ -47,14 +47,14 @@ func (v *ProxyConfigurationWebhook) Handle(ctx context.Context, req admission.Re
return common.ValidateMeshConfig(ctx, req, v.Logger, v, &resource, v.ConsulTenancyConfig)
}

func (v *ProxyConfigurationWebhook) List(ctx context.Context) ([]common.MeshConfig, error) {
func (v *ProxyConfigurationWebhook) List(ctx context.Context) ([]common.ConsulResource, error) {
var resourceList ProxyConfigurationList
if err := v.Client.List(ctx, &resourceList); err != nil {
return nil, err
}
var entries []common.MeshConfig
var entries []common.ConsulResource
for _, item := range resourceList.Items {
entries = append(entries, common.MeshConfig(item))
entries = append(entries, common.ConsulResource(item))
}
return entries, nil
}
Expand Down
8 changes: 4 additions & 4 deletions control-plane/api/mesh/v2beta1/tcp_route_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type TCPRouteWebhook struct {
client.Client
}

var _ common.MeshConfigLister = &TCPRouteWebhook{}
var _ common.ConsulResourceLister = &TCPRouteWebhook{}

// NOTE: The path value in the below line is the path to the webhook.
// If it is updated, run code-gen, update subcommand/inject-connect/command.go
Expand All @@ -47,14 +47,14 @@ func (v *TCPRouteWebhook) Handle(ctx context.Context, req admission.Request) adm
return common.ValidateMeshConfig(ctx, req, v.Logger, v, &resource, v.ConsulTenancyConfig)
}

func (v *TCPRouteWebhook) List(ctx context.Context) ([]common.MeshConfig, error) {
func (v *TCPRouteWebhook) List(ctx context.Context) ([]common.ConsulResource, error) {
var resourceList TCPRouteList
if err := v.Client.List(ctx, &resourceList); err != nil {
return nil, err
}
var entries []common.MeshConfig
var entries []common.ConsulResource
for _, item := range resourceList.Items {
entries = append(entries, common.MeshConfig(item))
entries = append(entries, common.ConsulResource(item))
}
return entries, nil
}
Expand Down
Loading