diff --git a/pkg/printers/internalversion/BUILD b/pkg/printers/internalversion/BUILD index 4c9bc328bb4..54146b92f74 100644 --- a/pkg/printers/internalversion/BUILD +++ b/pkg/printers/internalversion/BUILD @@ -103,7 +103,6 @@ go_library( "//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/duration:go_default_library", "//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library", - "//staging/src/k8s.io/apiserver/pkg/authentication/user:go_default_library", ], ) diff --git a/pkg/printers/internalversion/printers.go b/pkg/printers/internalversion/printers.go index 3c81140b69f..d1b878872ba 100644 --- a/pkg/printers/internalversion/printers.go +++ b/pkg/printers/internalversion/printers.go @@ -46,7 +46,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/util/duration" "k8s.io/apimachinery/pkg/util/sets" - "k8s.io/apiserver/pkg/authentication/user" "k8s.io/kubernetes/pkg/apis/admissionregistration" "k8s.io/kubernetes/pkg/apis/apps" "k8s.io/kubernetes/pkg/apis/autoscaling" @@ -527,8 +526,8 @@ func AddHandlers(h printers.PrintHandler) { {Name: "PriorityLevel", Type: "string", Description: flowcontrolv1alpha1.PriorityLevelConfigurationReference{}.SwaggerDoc()["name"]}, {Name: "MatchingPrecedence", Type: "string", Description: flowcontrolv1alpha1.FlowSchemaSpec{}.SwaggerDoc()["matchingPrecedence"]}, {Name: "DistinguisherMethod", Type: "string", Description: flowcontrolv1alpha1.FlowSchemaSpec{}.SwaggerDoc()["distinguisherMethod"]}, - {Name: "MatchesAll", Type: "bolean", Description: "matches all requests"}, {Name: "Age", Type: "string", Description: metav1.ObjectMeta{}.SwaggerDoc()["creationTimestamp"]}, + {Name: "MissingPL", Type: "string", Description: "references a broken or non-existent PriorityLevelConfiguration"}, } h.TableHandler(flowSchemaColumnDefinitions, printFlowSchema) h.TableHandler(flowSchemaColumnDefinitions, printFlowSchemaList) @@ -2272,51 +2271,6 @@ func printVolumeAttachmentList(list *storage.VolumeAttachmentList, options print return rows, nil } -func fsMatchesAll(obj *flowcontrol.FlowSchema) bool { - var allResources, allNonResources [2]bool - for _, prws := range obj.Spec.Rules { - allAuth, allUnauth := false, false - for _, subj := range prws.Subjects { - if subj.Group == nil { - continue - } - allAuth = allAuth || subj.Group.Name == user.AllAuthenticated - allUnauth = allUnauth || subj.Group.Name == user.AllUnauthenticated - } - anyAll := allAuth || allUnauth - if !anyAll { - continue - } - for _, nrr := range prws.NonResourceRules { - if hasWildcard(nrr.Verbs) && hasWildcard(nrr.NonResourceURLs) { - allNonResources[0] = allNonResources[0] || allAuth - allNonResources[1] = allNonResources[1] || allUnauth - break - } - } - for _, rr := range prws.ResourceRules { - if hasWildcard(rr.Verbs) && hasWildcard(rr.APIGroups) && hasWildcard(rr.Resources) && rr.ClusterScope && hasWildcard(rr.Namespaces) { - allResources[0] = allResources[0] || allAuth - allResources[1] = allResources[1] || allUnauth - break - } - } - if allResources[0] && allResources[1] && allNonResources[0] && allNonResources[1] { - return true - } - } - return false -} - -func hasWildcard(arr []string) bool { - for _, elt := range arr { - if elt == "*" { - return true - } - } - return false -} - func printFlowSchema(obj *flowcontrol.FlowSchema, options printers.GenerateOptions) ([]metav1.TableRow, error) { row := metav1.TableRow{ Object: runtime.RawExtension{Object: obj}, @@ -2328,7 +2282,14 @@ func printFlowSchema(obj *flowcontrol.FlowSchema, options printers.GenerateOptio if obj.Spec.DistinguisherMethod != nil { distinguisherMethod = string(obj.Spec.DistinguisherMethod.Type) } - row.Cells = append(row.Cells, name, plName, obj.Spec.MatchingPrecedence, distinguisherMethod, fsMatchesAll(obj), translateTimestampSince(obj.CreationTimestamp)) + badPLRef := "?" + for _, cond := range obj.Status.Conditions { + if cond.Type == flowcontrol.FlowSchemaConditionDangling { + badPLRef = string(cond.Status) + break + } + } + row.Cells = append(row.Cells, name, plName, obj.Spec.MatchingPrecedence, distinguisherMethod, translateTimestampSince(obj.CreationTimestamp), badPLRef) return []metav1.TableRow{row}, nil } diff --git a/pkg/printers/internalversion/printers_test.go b/pkg/printers/internalversion/printers_test.go index bd646fb3901..a45ad60d169 100644 --- a/pkg/printers/internalversion/printers_test.go +++ b/pkg/printers/internalversion/printers_test.go @@ -4890,8 +4890,8 @@ func TestPrintFlowSchema(t *testing.T) { }}, }, }, - // Columns: Name, PriorityLevelName, MatchingPrecedence, DistinguisherMethod, MatchesAll, Age - expected: []metav1.TableRow{{Cells: []interface{}{"all-matcher", "allee", int32(math.MaxInt32), "ByUser", true, "0s"}}}, + // Columns: Name, PriorityLevelName, MatchingPrecedence, DistinguisherMethod, Age, MissingPL + expected: []metav1.TableRow{{Cells: []interface{}{"all-matcher", "allee", int32(math.MaxInt32), "ByUser", "0s", "?"}}}, }, { fs: flowcontrol.FlowSchema{ ObjectMeta: metav1.ObjectMeta{ @@ -4928,9 +4928,16 @@ func TestPrintFlowSchema(t *testing.T) { }}, }}, }, + Status: flowcontrol.FlowSchemaStatus{ + Conditions: []flowcontrol.FlowSchemaCondition{{ + Type: flowcontrol.FlowSchemaConditionDangling, + Status: "True", + LastTransitionTime: metav1.Time{Time: time.Now().Add(-time.Hour)}, + }}, + }, }, - // Columns: Name, PriorityLevelName, MatchingPrecedence, DistinguisherMethod, MatchesAll, Age - expected: []metav1.TableRow{{Cells: []interface{}{"some-matcher", "allee", int32(0), "ByNamespace", false, "5m"}}}, + // Columns: Name, PriorityLevelName, MatchingPrecedence, DistinguisherMethod, Age, MissingPL + expected: []metav1.TableRow{{Cells: []interface{}{"some-matcher", "allee", int32(0), "ByNamespace", "5m", "True"}}}, }, { fs: flowcontrol.FlowSchema{ ObjectMeta: metav1.ObjectMeta{ @@ -4956,8 +4963,8 @@ func TestPrintFlowSchema(t *testing.T) { }}, }, }, - // Columns: Name, PriorityLevelName, MatchingPrecedence, DistinguisherMethod, MatchesAll, Age - expected: []metav1.TableRow{{Cells: []interface{}{"exempt", "allee", int32(0), "", false, "5m"}}}, + // Columns: Name, PriorityLevelName, MatchingPrecedence, DistinguisherMethod, Age, MissingPL + expected: []metav1.TableRow{{Cells: []interface{}{"exempt", "allee", int32(0), "", "5m", "?"}}}, }, }