m/n/k/reconciler: refactor resource interface
Replace interface{} with meta.Object, an interface which provides
accessors for and is implemented by meta.ObjectMeta. List now returns
the objects themselves instead of their names. This makes the reconciler
slightly less generic, as it now only supports kubernetes objects.
This is a refactoring in preparation for implementing updates in the
reconciler. There should be no change in behavior.
Change-Id: I97a4b1c0166a1e6fd0f247ee04e7c44cff570fd7
Reviewed-on: https://review.monogon.dev/c/monogon/+/2891
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
Tested-by: Jenkins CI
Vouch-Run-CI: Lorenz Brun <lorenz@monogon.tech>
diff --git a/metropolis/node/kubernetes/reconciler/resources_podsecuritypolicy.go b/metropolis/node/kubernetes/reconciler/resources_podsecuritypolicy.go
index 507089f..97a38dd 100644
--- a/metropolis/node/kubernetes/reconciler/resources_podsecuritypolicy.go
+++ b/metropolis/node/kubernetes/reconciler/resources_podsecuritypolicy.go
@@ -29,19 +29,19 @@
kubernetes.Interface
}
-func (r resourcePodSecurityPolicies) List(ctx context.Context) ([]string, error) {
+func (r resourcePodSecurityPolicies) List(ctx context.Context) ([]meta.Object, error) {
res, err := r.PolicyV1beta1().PodSecurityPolicies().List(ctx, listBuiltins)
if err != nil {
return nil, err
}
- objs := make([]string, len(res.Items))
- for i, el := range res.Items {
- objs[i] = el.ObjectMeta.Name
+ objs := make([]meta.Object, len(res.Items))
+ for i := range res.Items {
+ objs[i] = &res.Items[i]
}
return objs, nil
}
-func (r resourcePodSecurityPolicies) Create(ctx context.Context, el interface{}) error {
+func (r resourcePodSecurityPolicies) Create(ctx context.Context, el meta.Object) error {
_, err := r.PolicyV1beta1().PodSecurityPolicies().Create(ctx, el.(*policy.PodSecurityPolicy), meta.CreateOptions{})
return err
}
@@ -50,9 +50,9 @@
return r.PolicyV1beta1().PodSecurityPolicies().Delete(ctx, name, meta.DeleteOptions{})
}
-func (r resourcePodSecurityPolicies) Expected() map[string]interface{} {
- return map[string]interface{}{
- "default": &policy.PodSecurityPolicy{
+func (r resourcePodSecurityPolicies) Expected() []meta.Object {
+ return []meta.Object{
+ &policy.PodSecurityPolicy{
ObjectMeta: meta.ObjectMeta{
Name: "default",
Labels: builtinLabels(nil),