mirror of
https://github.com/projectcapsule/capsule.git
synced 2026-08-19 04:26:45 +00:00
fix: metric recorders for all conditionals (#1998)
* fix(controller): decode old object for delete requests Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore: modernize golang Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore: modernize golang Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * chore: modernize golang Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> * fix: preserve ca-bundles injected from external providers Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * feat: add metadata enforcement Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * feat: add metadata enforcement Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * fix: add resourcepoolclaim validation Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * fix: add resourcepoolclaim validation Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * fix: add resourcepoolclaim validation Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * fix: add resourcepoolclaim validation Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * fix: wave of fixes Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * fix: wave of fixes Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * fix: wave of fixes Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * fix: wave of fixes Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * fix: wave of fixes Signed-off-by: Oliver Baehler <oliver@sudo-i.net> * fix: wave of fixes Signed-off-by: Oliver Baehler <oliver@sudo-i.net> --------- Signed-off-by: Oliver Bähler <oliverbaehler@hotmail.com> Signed-off-by: Oliver Baehler <oliver@sudo-i.net> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Copilot Autofix powered by AI
parent
8e1cc910bd
commit
4b07463705
@@ -27,7 +27,7 @@ func (g GlobalCreatedItems) Func() client.IndexerFunc {
|
||||
|
||||
for _, pi := range tgr.Status.ProcessedItems {
|
||||
if pi.Created {
|
||||
out = append(out, pi.GetGVKKey(""))
|
||||
out = append(out, processedItemKey(pi))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ func (g GlobalProcessedItems) Func() client.IndexerFunc {
|
||||
|
||||
out := make([]string, 0, len(tgr.Status.ProcessedItems))
|
||||
for _, pi := range tgr.Status.ProcessedItems {
|
||||
out = append(out, pi.GetGVKKey(""))
|
||||
out = append(out, processedItemKey(pi))
|
||||
}
|
||||
|
||||
return out
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// Copyright 2020-2026 Project Capsule Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package tenantresource
|
||||
|
||||
import "github.com/projectcapsule/capsule/pkg/api/meta"
|
||||
|
||||
func processedItemKey(item meta.ObjectReferenceStatus) string {
|
||||
ref := item.ResourceID
|
||||
if item.ClusterScoped {
|
||||
ref.Namespace = ""
|
||||
}
|
||||
|
||||
return ref.GetGVKKey("")
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
// Copyright 2020-2026 Project Capsule Authors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package tenantresource
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
capsulev1beta2 "github.com/projectcapsule/capsule/api/v1beta2"
|
||||
"github.com/projectcapsule/capsule/pkg/api/meta"
|
||||
"github.com/projectcapsule/capsule/pkg/runtime/gvk"
|
||||
)
|
||||
|
||||
func TestCreatedItemsIndexersUseAdmissionKeyForClusterScopedItems(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
item := meta.ObjectReferenceStatus{
|
||||
ResourceID: gvk.ResourceID{
|
||||
Group: "rbac.authorization.k8s.io",
|
||||
Version: "v1",
|
||||
Kind: "ClusterRole",
|
||||
Namespace: "tenant-a",
|
||||
Name: "example",
|
||||
},
|
||||
ObjectReferenceStatusCondition: meta.ObjectReferenceStatusCondition{
|
||||
Created: true,
|
||||
ClusterScoped: true,
|
||||
},
|
||||
}
|
||||
|
||||
want := []string{
|
||||
gvk.ResourceID{
|
||||
Group: "rbac.authorization.k8s.io",
|
||||
Version: "v1",
|
||||
Kind: "ClusterRole",
|
||||
Name: "example",
|
||||
}.GetGVKKey(""),
|
||||
}
|
||||
|
||||
t.Run("global", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
idx := GlobalCreatedItems{}
|
||||
obj := &capsulev1beta2.GlobalTenantResource{}
|
||||
obj.Status.ProcessedItems = meta.ProcessedItems{item}
|
||||
|
||||
if got := idx.Func()(obj); !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("unexpected keys\nwant=%#v\ngot =%#v", want, got)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("namespaced", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
idx := NamespacedCreatedItems{}
|
||||
obj := &capsulev1beta2.TenantResource{}
|
||||
obj.Status.ProcessedItems = meta.ProcessedItems{item}
|
||||
|
||||
if got := idx.Func()(obj); !reflect.DeepEqual(got, want) {
|
||||
t.Fatalf("unexpected keys\nwant=%#v\ngot =%#v", want, got)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestProcessedItemKeyKeepsNamespaceForNamespacedItems(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
item := meta.ObjectReferenceStatus{
|
||||
ResourceID: gvk.ResourceID{
|
||||
Version: "v1",
|
||||
Kind: "Secret",
|
||||
Namespace: "tenant-a",
|
||||
Name: "example",
|
||||
},
|
||||
}
|
||||
|
||||
want := item.GetGVKKey("")
|
||||
|
||||
if got := processedItemKey(item); got != want {
|
||||
t.Fatalf("unexpected key: want %q, got %q", want, got)
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ func (g NamespacedCreatedItems) Func() client.IndexerFunc {
|
||||
|
||||
for _, pi := range tgr.Status.ProcessedItems {
|
||||
if pi.Created {
|
||||
out = append(out, pi.GetGVKKey(""))
|
||||
out = append(out, processedItemKey(pi))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ func (g NamespacedProcessedItems) Func() client.IndexerFunc {
|
||||
|
||||
out := make([]string, 0, len(tgr.Status.ProcessedItems))
|
||||
for _, pi := range tgr.Status.ProcessedItems {
|
||||
out = append(out, pi.GetGVKKey(""))
|
||||
out = append(out, processedItemKey(pi))
|
||||
}
|
||||
|
||||
return out
|
||||
|
||||
Reference in New Issue
Block a user