forked from kubernetes/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for IngressClass [kubernetes#5232]
- Loading branch information
1 parent
5a68519
commit d321adf
Showing
36 changed files
with
2,591 additions
and
1,212 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2017 The Kubernetes Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package ingressclass | ||
|
||
import ( | ||
"github.com/kubernetes/dashboard/src/app/backend/resource/dataselect" | ||
networkingv1 "k8s.io/api/networking/v1" | ||
) | ||
|
||
// The code below allows to perform complex data section on []networkingv1.IngressClass | ||
|
||
type IngressClassCell networkingv1.IngressClass | ||
|
||
func (self IngressClassCell) GetProperty(name dataselect.PropertyName) dataselect.ComparableValue { | ||
switch name { | ||
case dataselect.NameProperty: | ||
return dataselect.StdComparableString(self.ObjectMeta.Name) | ||
case dataselect.CreationTimestampProperty: | ||
return dataselect.StdComparableTime(self.ObjectMeta.CreationTimestamp.Time) | ||
case dataselect.NamespaceProperty: | ||
return dataselect.StdComparableString(self.ObjectMeta.Namespace) | ||
default: | ||
// if name is not supported then just return a constant dummy value, sort will have no effect. | ||
return nil | ||
} | ||
} | ||
|
||
func toCells(std []networkingv1.IngressClass) []dataselect.DataCell { | ||
cells := make([]dataselect.DataCell, len(std)) | ||
for i := range std { | ||
cells[i] = IngressClassCell(std[i]) | ||
} | ||
return cells | ||
} | ||
|
||
func fromCells(cells []dataselect.DataCell) []networkingv1.IngressClass { | ||
std := make([]networkingv1.IngressClass, len(cells)) | ||
for i := range std { | ||
std[i] = networkingv1.IngressClass(cells[i].(IngressClassCell)) | ||
} | ||
return std | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2017 The Kubernetes Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package ingressclass | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
networkingv1 "k8s.io/api/networking/v1" | ||
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
// IngressClassDetail provides the presentation layer view of Ingress Class resource. | ||
type IngressClassDetail struct { | ||
// Extends list item structure. | ||
IngressClass `json:",inline"` | ||
Parameters map[string]string `json:"parameters"` | ||
} | ||
|
||
// GetIngressClass returns Storage Class resource. | ||
func GetIngressClass(client kubernetes.Interface, name string) (*IngressClassDetail, error) { | ||
log.Printf("Getting details of %s ingress class", name) | ||
|
||
ic, err := client.NetworkingV1().IngressClasses().Get(context.TODO(), name, metaV1.GetOptions{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
ingressClass := toIngressClassDetail(ic) | ||
return &ingressClass, err | ||
} | ||
|
||
func toIngressClassDetail(ingressClass *networkingv1.IngressClass) IngressClassDetail { | ||
parametersMap := make(map[string]string) | ||
parameters := ingressClass.Spec.Parameters | ||
if parameters != nil { | ||
// Mandatory parameters | ||
parametersMap["Kind"] = parameters.Kind | ||
parametersMap["Name"] = parameters.Name | ||
// Optional parameters | ||
if parameters.APIGroup != nil { | ||
parametersMap["ApiGroup"] = *parameters.APIGroup | ||
} | ||
if parameters.Namespace != nil { | ||
parametersMap["Namespace"] = *parameters.Namespace | ||
} | ||
if parameters.Scope != nil { | ||
parametersMap["Scope"] = *parameters.Scope | ||
} | ||
} | ||
return IngressClassDetail{ | ||
IngressClass: toIngressClass(ingressClass), | ||
Parameters: parametersMap, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Copyright 2017 The Kubernetes Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package ingressclass | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/kubernetes/dashboard/src/app/backend/api" | ||
networkingv1 "k8s.io/api/networking/v1" | ||
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestToIngressClassDetails(t *testing.T) { | ||
paramRef := networkingv1.IngressClassParametersReference{Kind: "pods", Name: "test"} | ||
apiGroup := "k8s.example.com" | ||
scope := "Namespace" | ||
paramFullRef := networkingv1.IngressClassParametersReference{Kind: "pods", Name: "test", APIGroup: &apiGroup, Scope: &scope} | ||
cases := []struct { | ||
ingressClass *networkingv1.IngressClass | ||
expected IngressClassDetail | ||
}{ | ||
{ | ||
ingressClass: &networkingv1.IngressClass{ | ||
ObjectMeta: metaV1.ObjectMeta{Name: "test-ic"}, | ||
Spec: networkingv1.IngressClassSpec{Controller: "k8s.io/ingress-nginx", Parameters: ¶mRef}, | ||
}, | ||
expected: IngressClassDetail{ | ||
IngressClass: IngressClass{ | ||
ObjectMeta: api.ObjectMeta{Name: "test-ic"}, | ||
TypeMeta: api.TypeMeta{Kind: "ingressclass"}, | ||
Controller: "k8s.io/ingress-nginx"}, | ||
Parameters: map[string]string{"Kind": "pods", "Name": "test"}, | ||
}, | ||
}, { | ||
ingressClass: &networkingv1.IngressClass{ | ||
ObjectMeta: metaV1.ObjectMeta{Name: "test-ic"}, | ||
Spec: networkingv1.IngressClassSpec{Controller: "k8s.io/ingress-nginx", Parameters: ¶mFullRef}, | ||
}, | ||
expected: IngressClassDetail{ | ||
IngressClass: IngressClass{ | ||
ObjectMeta: api.ObjectMeta{Name: "test-ic"}, | ||
TypeMeta: api.TypeMeta{Kind: "ingressclass"}, | ||
Controller: "k8s.io/ingress-nginx"}, | ||
Parameters: map[string]string{"ApiGroup": "k8s.example.com", "Kind": "pods", "Name": "test", "Scope": "Namespace"}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, c := range cases { | ||
actual := toIngressClassDetail(c.ingressClass) | ||
|
||
if !reflect.DeepEqual(actual, c.expected) { | ||
t.Errorf("toIngressClassDetails(%#v) == \ngot %#v, \nexpected %#v", c.ingressClass, actual, c.expected) | ||
} | ||
} | ||
} |
Oops, something went wrong.