Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
dead945
UPSTREAM: 113151: Revert: Revert: Clean up CRD conversion code structure
sttts Sep 11, 2023
d157aea
README
sttts Sep 1, 2023
a0f3d68
UPSTREAM: <carry>: controlplane/apiserver: add miniaggregator
sttts Sep 27, 2023
7234f81
UPSTREAM: <carry>: clusterize controllers
sttts Sep 1, 2023
28ac217
UPSTREAM: <carry>: re-add GC worker locks
gman0 Feb 3, 2025
570c6ed
UPSTREAM: <carry>: Add kcp patchers
sttts Oct 8, 2023
c93e304
UPSTREAM: <carry>: re-generated pkg/controller/resourcequota/resource…
gman0 Jan 26, 2025
2016601
UPSTREAM: <carry>: re-generated pkg/controller/garbagecollector/garba…
gman0 Feb 11, 2025
f87a202
UPSTREAM: <carry>: storage: etcd cluster key computation
sttts Sep 27, 2023
aad4a42
UPSTREAM: <carry>: clusterize serviceaccounts
sttts Sep 1, 2023
86eb6a8
UPSTREAM: <carry>: registry/core/serviceaccount: do not crash without…
sttts Sep 27, 2023
0e41242
UPSTREAM: <carry>: kube-aggregator
sttts Sep 1, 2023
006648f
UPSTREAM: <carry>: INTERESTING: clusterize admission
sttts Sep 1, 2023
ba55bcf
UPSTREAM: <carry>: Clusterize ValidatingAdmissionPolicy admission plu…
embik Jul 24, 2024
aaa0e92
UPSTREAM: <carry>: clusterize storage hash
sttts Sep 27, 2023
f2ad525
UPSTREAM: <carry>: endpoints: add Cluster struct for ctx
sttts Sep 27, 2023
4ed5b98
UPSTREAM: <carry>: endpoints/patch: wire openapi for CRD strategic me…
sttts Sep 27, 2023
4739ef6
UPSTREAM: <carry>: storage/etcd3: clusterize
sttts Sep 27, 2023
ab335e9
UPSTREAM: <carry>: apiserver: partial wildcard metadata request accro…
sttts Sep 27, 2023
d868a62
UPSTREAM: <carry>: endpoints: set kcp.io/original-api-version on wild…
sttts Sep 27, 2023
7f28105
UPSTREAM: <carry>: watch(er/cache): clusterize
sttts Sep 27, 2023
e271562
UPSTREAM: <carry>: apiserver: split chain into pre and post authz
sttts Sep 27, 2023
4a2b5f9
UPSTREAM: <carry>: apiserver: clusterize listed paths
sttts Sep 27, 2023
b9669e3
UPSTREAM: <carry>: apiserver: clusterize OpenAPI v2
sttts Sep 27, 2023
b5939d8
UPSTREAM: <carry>: clusterize BuiltInAuthenticationOptions
sttts Sep 27, 2023
bf1a2a1
UPSTREAM: <carry>: storage: add UseResourceAsPrefixDefault for legacy…
sttts Sep 27, 2023
879e485
UPSTREAM: <carry>: apiextensions-apiserver
sttts Sep 27, 2023
0203da1
UPSTREAM: <carry>: cache-server: wire shard name into storage
sttts Sep 27, 2023
db825b7
UPSTREAM: <carry>: add client and informer hacks
sttts Sep 27, 2023
1159daa
UPSTREAM: <carry>: controlplane: wire informers and clients
sttts Sep 11, 2023
4c9c3df
UPSTREAM: <carry>: generic cleanup
mjudeikis Sep 3, 2024
ab917a9
UPSTREAM: <carry>: controlplane/apiserver: disable protobuf for loopback
sttts Sep 25, 2023
e142cc7
UPSTREAM: <carry>: pass system:admin clients and informers in generic…
embik Jun 13, 2024
a71d65e
UPSTREAM: <carry>: remove REST mapper from admission plugins
embik Jun 20, 2024
68b54d6
UPSTREAM: <carry>: provide supportedMediaTypes for custom resoure han…
embik Jun 21, 2024
50c9ea5
UPSTREAM: <carry>: prevent NPE if no authorization is set
embik Jun 21, 2024
2034abe
UPSTREAM: <carry>: wrap CRD group into packagePrefix for OpenAPIV3 bu…
embik Jul 12, 2024
8a207b8
UPSTREAM: <CARRY>: clusterize validatingadmissionpolicystatus controller
embik Jul 23, 2024
7a27a28
UPSTREAM: <carry>: apiserver cleaning
mjudeikis Sep 3, 2024
5c809ee
UPSTREAM: <squash>: remove syncer custom code from apiextensions-apis…
sttts Sep 18, 2024
fe0acf7
UPSTREAM: <carry>: include cluster name in authz SubjectAccessReview …
xrstf Nov 13, 2024
d57c237
UPSTREAM: <squash>: prevent conflict with pre-existing auth annotation
xrstf Nov 14, 2024
455d854
CARRY: split auth/authz chains even more
mjudeikis Dec 10, 2024
1a37a19
UPSTREAM: <carry>: authz: add scoping to default rule resolver
sttts Aug 23, 2024
b6ac17f
UPSTREAM: <carry>: authz: add warrants to default rule resolver
sttts Aug 23, 2024
dc03406
UPSTREAM: <squash>: authz: add warrants to default rule resolver: glo…
sttts Jan 24, 2025
b06d2a8
UPSTREAM: <squash>: authz: add warrants to default rule resolver: hel…
sttts Jan 24, 2025
1b0b146
UPSTREAM: <squash>: authz: add warrants to default rule resolver: glo…
sttts Jan 25, 2025
0ced631
UPSTREAM: <squash>: authz: add warrants to default rule resolver: for…
sttts Jan 25, 2025
bffed1d
UPSTREAM: <squash>: authz: add warrants to default rule resolver: sim…
sttts Jan 25, 2025
8fd95d6
UPSTREAM: <carry>: endpoints: wire in ctx to watchListTransformer
gman0 Jan 22, 2025
8befcaf
UPSTREAM: <carry>: Clusterize MutatingAdmissionPolicy admission plugi…
gman0 Jan 23, 2025
8fc9059
UPSTREAM: <carry>: don't use --prefers-protobuf with client-gen
gman0 Feb 10, 2025
03a3c1b
UPSTREAM: <drop>: Pinned kcp dependencies
gman0 Feb 12, 2025
204c308
UPSTREAM: <drop>: Updated vendor modules
gman0 Feb 12, 2025
c6ebc59
UPSTREAM: <drop>: Re-generated client code
gman0 Feb 12, 2025
89e1549
UPSTREAM 130180: Make disable lookups of SA related artifacts working
mjudeikis Feb 14, 2025
3b193fc
Merge pull request #163 from mjudeikis/mjudeikis/cherry.sa.lookup
mjudeikis Feb 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,25 @@ const (
resourceCountPollPeriodJitter = 1.2
)

// NoNamespaceKeyRootFunc is the default function for constructing storage paths
// to resource directories enforcing namespace rules.
func NoNamespaceKeyRootFunc(ctx context.Context, prefix string) string {
key := prefix
cluster, err := genericapirequest.ValidClusterFrom(ctx)
if err != nil {
klog.Errorf("invalid context cluster value: %v", err)
return key
}
if !cluster.Wildcard {
key += "/" + cluster.Name.String()
}
return key
}

// NamespaceKeyRootFunc is the default function for constructing storage paths
// to resource directories enforcing namespace rules.
func NamespaceKeyRootFunc(ctx context.Context, prefix string) string {
key := prefix
key := NoNamespaceKeyRootFunc(ctx, prefix)
ns, ok := genericapirequest.NamespaceFrom(ctx)
if ok && len(ns) > 0 {
key = key + "/" + ns
Expand All @@ -278,7 +293,6 @@ func NamespaceKeyRootFunc(ctx context.Context, prefix string) string {
// a resource relative to the given prefix enforcing namespace rules. If the
// context does not contain a namespace, it errors.
func NamespaceKeyFunc(ctx context.Context, prefix string, name string) (string, error) {
key := NamespaceKeyRootFunc(ctx, prefix)
ns, ok := genericapirequest.NamespaceFrom(ctx)
if !ok || len(ns) == 0 {
return "", apierrors.NewBadRequest("Namespace parameter required.")
Expand All @@ -289,8 +303,7 @@ func NamespaceKeyFunc(ctx context.Context, prefix string, name string) (string,
if msgs := path.IsValidPathSegmentName(name); len(msgs) != 0 {
return "", apierrors.NewBadRequest(fmt.Sprintf("Name parameter invalid: %q: %s", name, strings.Join(msgs, ";")))
}
key = key + "/" + name
return key, nil
return NoNamespaceKeyRootFunc(ctx, prefix) + "/" + ns + "/" + name, nil
}

// NoNamespaceKeyFunc is the default function for constructing storage paths
Expand All @@ -302,8 +315,7 @@ func NoNamespaceKeyFunc(ctx context.Context, prefix string, name string) (string
if msgs := path.IsValidPathSegmentName(name); len(msgs) != 0 {
return "", apierrors.NewBadRequest(fmt.Sprintf("Name parameter invalid: %q: %s", name, strings.Join(msgs, ";")))
}
key := prefix + "/" + name
return key, nil
return NoNamespaceKeyRootFunc(ctx, prefix) + "/" + name, nil
}

// New implements RESTStorage.New.
Expand Down Expand Up @@ -478,7 +490,8 @@ func (e *Store) create(ctx context.Context, obj runtime.Object, createValidation
var finishCreate FinishFunc = finishNothing

// Init metadata as early as possible.
if objectMeta, err := meta.Accessor(obj); err != nil {
objectMeta, err := meta.Accessor(obj)
if err != nil {
return nil, err
} else {
rest.FillObjectMetaSystemFields(objectMeta)
Expand Down Expand Up @@ -1504,6 +1517,9 @@ func (e *Store) CompleteWithOptions(options *generic.StoreOptions) error {
if (e.KeyRootFunc == nil) != (e.KeyFunc == nil) {
return fmt.Errorf("store for %s must set both KeyRootFunc and KeyFunc or neither", e.DefaultQualifiedResource.String())
}
if e.KeyFunc != nil || e.KeyFunc != nil {
return fmt.Errorf("DEBUG: keyfunc must be non-nil for all resources", e.DefaultQualifiedResource.String())
}

if e.TableConvertor == nil {
return fmt.Errorf("store for %s must set TableConvertor; rest.NewDefaultTableConvertor(e.DefaultQualifiedResource) can be used to output just name/creation time", e.DefaultQualifiedResource.String())
Expand Down Expand Up @@ -1564,6 +1580,13 @@ func (e *Store) CompleteWithOptions(options *generic.StoreOptions) error {
return fmt.Errorf("store for %s has an invalid prefix %q", e.DefaultQualifiedResource.String(), opts.ResourcePrefix)
}

if e.KeyFunc != nil {
panic(fmt.Sprintf("KeyFunc is illegal for %v: %T", e.DefaultQualifiedResource, e.KeyFunc))
}
if e.KeyRootFunc != nil {
panic(fmt.Sprintf("KeyRootFunc is illegal for %v: %T", e.DefaultQualifiedResource, e.KeyRootFunc))
}

// Set the default behavior for storage key generation
if e.KeyRootFunc == nil && e.KeyFunc == nil {
if isNamespaced {
Expand All @@ -1575,7 +1598,7 @@ func (e *Store) CompleteWithOptions(options *generic.StoreOptions) error {
}
} else {
e.KeyRootFunc = func(ctx context.Context) string {
return prefix
return NoNamespaceKeyRootFunc(ctx, prefix)
}
e.KeyFunc = func(ctx context.Context, name string) (string, error) {
return NoNamespaceKeyFunc(ctx, prefix, name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"testing"
"time"

"github.com/kcp-dev/logicalcluster/v3"
apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -102,10 +103,14 @@ func (t *Tester) TestNamespace() string {
return "test"
}

func (t *Tester) TestCluster() logicalcluster.Name {
return logicalcluster.New("root")
}

// TestContext returns a namespaced context that will be used when making storage calls.
// Namespace is determined by TestNamespace()
func (t *Tester) TestContext() context.Context {
return genericapirequest.WithNamespace(genericapirequest.NewContext(), t.TestNamespace())
return genericapirequest.WithCluster(genericapirequest.WithNamespace(genericapirequest.NewContext(), t.TestNamespace()), genericapirequest.Cluster{Name: t.TestCluster()})
}

func (t *Tester) getObjectMetaOrFail(obj runtime.Object) metav1.Object {
Expand Down Expand Up @@ -314,6 +319,7 @@ func (t *Tester) testCreateDryRunEquals(obj runtime.Object) {
createdFakeMeta.SetResourceVersion("")
createdMeta.SetResourceVersion("")
createdMeta.SetUID(createdFakeMeta.GetUID())
createdMeta.SetZZZ_DeprecatedClusterName(createdFakeMeta.GetZZZ_DeprecatedClusterName())

if e, a := created, createdFake; !apiequality.Semantic.DeepEqual(e, a) {
t.Errorf("unexpected obj: %#v, expected %#v", e, a)
Expand Down Expand Up @@ -341,6 +347,7 @@ func (t *Tester) testCreateEquals(obj runtime.Object, getFn GetFunc) {
createdMeta := t.getObjectMetaOrFail(created)
gotMeta := t.getObjectMetaOrFail(got)
createdMeta.SetResourceVersion(gotMeta.GetResourceVersion())
createdMeta.SetZZZ_DeprecatedClusterName(gotMeta.GetZZZ_DeprecatedClusterName())

if e, a := created, got; !apiequality.Semantic.DeepEqual(e, a) {
t.Errorf("unexpected obj: %#v, expected %#v", e, a)
Expand Down Expand Up @@ -402,7 +409,7 @@ func (t *Tester) testCreateHasMetadata(valid runtime.Object) {

func (t *Tester) testCreateIgnoresContextNamespace(valid runtime.Object, opts metav1.CreateOptions) {
// Ignore non-empty namespace in context
ctx := genericapirequest.WithNamespace(genericapirequest.NewContext(), "not-default2")
ctx := genericapirequest.WithNamespace(genericapirequest.WithCluster(genericapirequest.NewContext(), genericapirequest.Cluster{Name: t.TestCluster()}), "not-default2")

// Ideally, we'd get an error back here, but at least verify the namespace wasn't persisted
created, err := t.storage.(rest.Creater).Create(ctx, valid.DeepCopyObject(), rest.ValidateAllObjectFunc, &opts)
Expand All @@ -421,7 +428,7 @@ func (t *Tester) testCreateIgnoresMismatchedNamespace(valid runtime.Object, opts

// Ignore non-empty namespace in object meta
objectMeta.SetNamespace("not-default")
ctx := genericapirequest.WithNamespace(genericapirequest.NewContext(), "not-default2")
ctx := genericapirequest.WithNamespace(genericapirequest.WithCluster(genericapirequest.NewContext(), genericapirequest.Cluster{Name: t.TestCluster()}), "not-default2")

// Ideally, we'd get an error back here, but at least verify the namespace wasn't persisted
created, err := t.storage.(rest.Creater).Create(ctx, valid.DeepCopyObject(), rest.ValidateAllObjectFunc, &opts)
Expand Down Expand Up @@ -1164,14 +1171,14 @@ func (t *Tester) testGetDifferentNamespace(obj runtime.Object) {
objMeta := t.getObjectMetaOrFail(obj)
objMeta.SetName(t.namer(5))

ctx1 := genericapirequest.WithNamespace(genericapirequest.NewContext(), "bar3")
ctx1 := genericapirequest.WithNamespace(genericapirequest.WithCluster(genericapirequest.NewContext(), genericapirequest.Cluster{Name: t.TestCluster()}), "bar3")
objMeta.SetNamespace(genericapirequest.NamespaceValue(ctx1))
_, err := t.storage.(rest.Creater).Create(ctx1, obj, rest.ValidateAllObjectFunc, &metav1.CreateOptions{})
if err != nil {
t.Errorf("unexpected error: %v", err)
}

ctx2 := genericapirequest.WithNamespace(genericapirequest.NewContext(), "bar4")
ctx2 := genericapirequest.WithNamespace(genericapirequest.WithCluster(genericapirequest.NewContext(), genericapirequest.Cluster{Name: t.TestCluster()}), "bar4")
objMeta.SetNamespace(genericapirequest.NamespaceValue(ctx2))
_, err = t.storage.(rest.Creater).Create(ctx2, obj, rest.ValidateAllObjectFunc, &metav1.CreateOptions{})
if err != nil {
Expand Down Expand Up @@ -1225,8 +1232,8 @@ func (t *Tester) testGetFound(obj runtime.Object) {
}

func (t *Tester) testGetMimatchedNamespace(obj runtime.Object) {
ctx1 := genericapirequest.WithNamespace(genericapirequest.NewContext(), "bar1")
ctx2 := genericapirequest.WithNamespace(genericapirequest.NewContext(), "bar2")
ctx1 := genericapirequest.WithNamespace(genericapirequest.WithCluster(genericapirequest.NewContext(), genericapirequest.Cluster{Name: t.TestCluster()}), "bar1")
ctx2 := genericapirequest.WithNamespace(genericapirequest.WithCluster(genericapirequest.NewContext(), genericapirequest.Cluster{Name: t.TestCluster()}), "bar2")
objMeta := t.getObjectMetaOrFail(obj)
objMeta.SetName(t.namer(4))
objMeta.SetNamespace(genericapirequest.NamespaceValue(ctx1))
Expand Down Expand Up @@ -1319,7 +1326,7 @@ func (t *Tester) testListMatchLabels(obj runtime.Object, assignFn AssignFunc) {
foo4Meta.SetNamespace(genericapirequest.NamespaceValue(ctx))
foo4Meta.SetLabels(testLabels)

objs := ([]runtime.Object{foo3, foo4})
objs := []runtime.Object{foo3, foo4}

assignFn(objs)
filtered := []runtime.Object{objs[1]}
Expand Down Expand Up @@ -1373,7 +1380,7 @@ func (t *Tester) testListTableConversion(obj runtime.Object, assignFn AssignFunc
foo4Meta.SetNamespace(genericapirequest.NamespaceValue(ctx))
foo4Meta.SetLabels(testLabels)

objs := ([]runtime.Object{foo3, foo4})
objs := []runtime.Object{foo3, foo4}

assignFn(objs)

Expand Down