mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-16 06:32:32 +00:00
Add default namespace labels to all namespaces for selectors (#96968)
* namespace by name default labelling Co-authored-by: Jordan Liggitt <jordan@liggitt.net> Co-authored-by: Abhishek Raut <rauta@vmware.com> * Make some logic improvement into default namespace label * Fix unit tests * minor change to trigger the CI * Correct some tests and validation behaviors * Add Canonicalize normalization and improve validation * Remove label validation that should be dealt by strategy * Update defaults_test.go add fuzzer ns spec * remove the finalizer thingy * Fix integration test * Add namespace canonicalize unit test * Improve validation code and code comments * move validation of labels to validateupdate * spacex will save us all * add comment to testget * readablility of canonicalize * Added namespace finalize and status update validation * comment about ungenerated names * correcting a missing line on storage_test * Update the namespace validation unit test * Add more missing unit test changes * Let's just blast the value. Also documenting the workflow here * Remove unnecessary validations Co-authored-by: Jordan Liggitt <jordan@liggitt.net> Co-authored-by: Abhishek Raut <rauta@vmware.com> Co-authored-by: Ricardo Pchevuzinske Katz <ricardo.katz@gmail.com>
This commit is contained in:
@@ -19,6 +19,7 @@ package namespace
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -115,6 +116,39 @@ func TestNamespaceCondition(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestNamespaceLabels tests for default labels added in https://github.com/kubernetes/kubernetes/pull/96968
|
||||
func TestNamespaceLabels(t *testing.T) {
|
||||
closeFn, _, _, kubeClient, _ := namespaceLifecycleSetup(t)
|
||||
defer closeFn()
|
||||
nsName := "test-namespace-labels-generated"
|
||||
// Create a new namespace w/ no name
|
||||
ns, err := kubeClient.CoreV1().Namespaces().Create(context.TODO(), &corev1.Namespace{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
GenerateName: nsName,
|
||||
},
|
||||
}, metav1.CreateOptions{})
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if ns.Name != ns.Labels[corev1.LabelMetadataName] {
|
||||
t.Fatal(fmt.Errorf("expected %q, got %q", ns.Name, ns.Labels[corev1.LabelMetadataName]))
|
||||
}
|
||||
|
||||
nsList, err := kubeClient.CoreV1().Namespaces().List(context.TODO(), metav1.ListOptions{})
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, ns := range nsList.Items {
|
||||
if ns.Name != ns.Labels[corev1.LabelMetadataName] {
|
||||
t.Fatal(fmt.Errorf("expected %q, got %q", ns.Name, ns.Labels[corev1.LabelMetadataName]))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// JSONToUnstructured converts a JSON stub to unstructured.Unstructured and
|
||||
// returns a dynamic resource client that can be used to interact with it
|
||||
func jsonToUnstructured(stub, version, kind string) (*unstructured.Unstructured, error) {
|
||||
|
Reference in New Issue
Block a user