-
Notifications
You must be signed in to change notification settings - Fork 321
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
Stub mesh configuration resource controller #3302
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -50,13 +50,13 @@ type MeshConfigurationList struct { | |||||
Items []*MeshConfiguration `json:"items"` | ||||||
} | ||||||
|
||||||
func (in *MeshConfiguration) ResourceID(namespace, partition string) *pbresource.ID { | ||||||
func (in *MeshConfiguration) ResourceID(_, partition string) *pbresource.ID { | ||||||
return &pbresource.ID{ | ||||||
Name: in.Name, | ||||||
Type: pbmesh.MeshConfigurationType, | ||||||
Tenancy: &pbresource.Tenancy{ | ||||||
// we don't pass a namespace here because MeshConfiguration is partition-scoped | ||||||
Partition: partition, | ||||||
Namespace: namespace, | ||||||
|
||||||
// Because we are explicitly defining NS/partition, this will not default and must be explicit. | ||||||
// At a future point, this will move out of the Tenancy block. | ||||||
|
@@ -65,9 +65,9 @@ func (in *MeshConfiguration) ResourceID(namespace, partition string) *pbresource | |||||
} | ||||||
} | ||||||
|
||||||
func (in *MeshConfiguration) Resource(namespace, partition string) *pbresource.Resource { | ||||||
func (in *MeshConfiguration) Resource(_, partition string) *pbresource.Resource { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question as above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are both to implement the consul-k8s/control-plane/api/common/consul_resource.go Lines 15 to 16 in 46bf9bf
So I need to keep the arguments even though they're unused since the resource is purely partition scoped (it doesn't have a namespace). It's a much less invasive change on the shared controller -- alternatively we'd need to make the shared code aware of resources that are partition-scoped and treat them differently. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation |
||||||
return &pbresource.Resource{ | ||||||
Id: in.ResourceID(namespace, partition), | ||||||
Id: in.ResourceID("", partition), | ||||||
Data: inject.ToProtoAny(&in.Spec), | ||||||
Metadata: meshConfigMeta(), | ||||||
} | ||||||
|
@@ -91,9 +91,9 @@ func (in *MeshConfiguration) Finalizers() []string { | |||||
return in.ObjectMeta.Finalizers | ||||||
} | ||||||
|
||||||
func (in *MeshConfiguration) MatchesConsul(candidate *pbresource.Resource, namespace, partition string) bool { | ||||||
func (in *MeshConfiguration) MatchesConsul(candidate *pbresource.Resource, _, partition string) bool { | ||||||
return cmp.Equal( | ||||||
in.Resource(namespace, partition), | ||||||
in.Resource("", partition), | ||||||
candidate, | ||||||
protocmp.IgnoreFields(&pbresource.Resource{}, "status", "generation", "version"), | ||||||
protocmp.IgnoreFields(&pbresource.ID{}, "uid"), | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package controllersv2 | ||
|
||
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" | ||
|
||
meshv2beta1 "github.com/hashicorp/consul-k8s/control-plane/api/mesh/v2beta1" | ||
) | ||
|
||
// MeshConfigurationController reconciles a MeshConfiguration object. | ||
type MeshConfigurationController struct { | ||
client.Client | ||
Log logr.Logger | ||
Scheme *runtime.Scheme | ||
Controller *ConsulResourceController | ||
} | ||
|
||
// +kubebuilder:rbac:groups=mesh.consul.hashicorp.com,resources=meshconfiguration,verbs=get;list;watch;create;update;patch;delete | ||
// +kubebuilder:rbac:groups=mesh.consul.hashicorp.com,resources=meshconfiguration/status,verbs=get;update;patch | ||
|
||
func (r *MeshConfigurationController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { | ||
return r.Controller.ReconcileEntry(ctx, r, req, &meshv2beta1.MeshConfiguration{}) | ||
} | ||
|
||
func (r *MeshConfigurationController) Logger(name types.NamespacedName) logr.Logger { | ||
return r.Log.WithValues("request", name) | ||
} | ||
|
||
func (r *MeshConfigurationController) UpdateStatus(ctx context.Context, obj client.Object, opts ...client.SubResourceUpdateOption) error { | ||
return r.Status().Update(ctx, obj, opts...) | ||
} | ||
|
||
func (r *MeshConfigurationController) SetupWithManager(mgr ctrl.Manager) error { | ||
return setupWithManager(mgr, &meshv2beta1.MeshConfiguration{}, r) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use a blank identifier here as opposed to just removing the namespace parameter as it's no longer required?