Skip to content

Commit

Permalink
migrate ingress from extensions/v1beta1 to networking/v1 (#6664)
Browse files Browse the repository at this point in the history
* migrate ingress from extensions/v1beta1 to networking/v1

* so far so good

* no more customresourcedefinition/v1beta1

* last file

* we are now future proof for v2

* remove k8sClient.ExtensionsV1beta1().RESTClient()
  • Loading branch information
marcosdiez authored Dec 22, 2021
1 parent 254b752 commit 8b7e59a
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 633 deletions.
2 changes: 1 addition & 1 deletion src/app/backend/auth/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (self *fakeClientManager) HasAccess(authInfo api.AuthInfo) error {
}

func (self *fakeClientManager) VerberClient(req *restful.Request, config *rest.Config) (clientapi.ResourceVerber, error) {
return client.NewResourceVerber(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil), nil
return client.NewResourceVerber(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil), nil
}

func (self *fakeClientManager) CanI(req *restful.Request, ssar *v1.SelfSubjectAccessReview) bool {
Expand Down
1 change: 0 additions & 1 deletion src/app/backend/client/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ func (self *clientManager) VerberClient(req *restful.Request, config *rest.Confi

return NewResourceVerber(
k8sClient.CoreV1().RESTClient(),
k8sClient.ExtensionsV1beta1().RESTClient(),
k8sClient.AppsV1().RESTClient(),
k8sClient.BatchV1().RESTClient(),
k8sClient.BatchV1beta1().RESTClient(),
Expand Down
26 changes: 3 additions & 23 deletions src/app/backend/client/verber.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"

apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"

v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
restclient "k8s.io/client-go/rest"
Expand All @@ -34,7 +34,6 @@ import (
// DELETE, PUT, UPDATE.
type resourceVerber struct {
client RESTClient
extensionsClient RESTClient
appsClient RESTClient
batchClient RESTClient
betaBatchClient RESTClient
Expand All @@ -56,8 +55,6 @@ type crdInfo struct {

func (verber *resourceVerber) getRESTClientByType(clientType api.ClientType) RESTClient {
switch clientType {
case api.ClientTypeExtensionClient:
return verber.extensionsClient
case api.ClientTypeAppsClient:
return verber.appsClient
case api.ClientTypeBatchClient:
Expand Down Expand Up @@ -120,7 +117,6 @@ func (verber *resourceVerber) getResourceSpecFromKind(kind string, namespaceSet

func (verber *resourceVerber) getCRDGroupAndVersion(kind string) (info crdInfo, err error) {
var crdv1 apiextensionsv1.CustomResourceDefinition
var crdv1beta1 apiextensionsv1beta1.CustomResourceDefinition

err = verber.apiExtensionsClient.Get().Resource("customresourcedefinitions").Name(kind).Do(context.TODO()).Into(&crdv1)
if err != nil {
Expand All @@ -140,22 +136,6 @@ func (verber *resourceVerber) getCRDGroupAndVersion(kind string) (info crdInfo,
return
}

err = verber.apiExtensionsClient.Get().Resource("customresourcedefinitions").Name(kind).Do(context.TODO()).Into(&crdv1beta1)
if err != nil {
if errors.IsNotFoundError(err) {
return info, errors.NewInvalid(fmt.Sprintf("Unknown resource kind: %s", kind))
}

return
}

if len(crdv1beta1.Spec.Versions) > 0 {
info.group = crdv1beta1.Spec.Group
info.version = crdv1beta1.Spec.Versions[0].Name
info.pluralName = crdv1beta1.Status.AcceptedNames.Plural
info.namespaced = crdv1beta1.Spec.Scope == apiextensionsv1beta1.NamespaceScoped
}

return
}

Expand All @@ -167,8 +147,8 @@ type RESTClient interface {
}

// NewResourceVerber creates a new resource verber that uses the given client for performing operations.
func NewResourceVerber(client, extensionsClient, appsClient, batchClient, betaBatchClient, autoscalingClient, storageClient, rbacClient, networkingClient, apiExtensionsClient, pluginsClient RESTClient, config *restclient.Config) clientapi.ResourceVerber {
return &resourceVerber{client, extensionsClient, appsClient,
func NewResourceVerber(client, appsClient, batchClient, betaBatchClient, autoscalingClient, storageClient, rbacClient, networkingClient, apiExtensionsClient, pluginsClient RESTClient, config *restclient.Config) clientapi.ResourceVerber {
return &resourceVerber{client, appsClient,
batchClient, betaBatchClient, autoscalingClient, storageClient, rbacClient, networkingClient, apiExtensionsClient, pluginsClient, config}
}

Expand Down
10 changes: 4 additions & 6 deletions src/app/backend/client/verber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ func normalize(msg string) string {

func TestDeleteShouldPropagateErrorsAndChooseClient(t *testing.T) {
verber := resourceVerber{
client: &FakeRESTClient{err: errors.NewInvalid("err")},
extensionsClient: &FakeRESTClient{err: errors.NewInvalid("err from extensions")},
appsClient: &FakeRESTClient{err: errors.NewInvalid("err from apps")},
client: &FakeRESTClient{err: errors.NewInvalid("err")},
appsClient: &FakeRESTClient{err: errors.NewInvalid("err from apps")},
}

err := verber.Delete("replicaset", true, "bar", "baz")
Expand All @@ -106,9 +105,8 @@ func TestDeleteShouldPropagateErrorsAndChooseClient(t *testing.T) {

func TestGetShouldPropagateErrorsAndChoseClient(t *testing.T) {
verber := resourceVerber{
client: &FakeRESTClient{err: errors.NewInvalid("err")},
extensionsClient: &FakeRESTClient{err: errors.NewInvalid("err from extensions")},
appsClient: &FakeRESTClient{err: errors.NewInvalid("err from apps")},
client: &FakeRESTClient{err: errors.NewInvalid("err")},
appsClient: &FakeRESTClient{err: errors.NewInvalid("err from apps")},
}

_, err := verber.Get("replicaset", true, "bar", "baz")
Expand Down
37 changes: 6 additions & 31 deletions src/app/backend/resource/common/resourcechannels.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
batch "k8s.io/api/batch/v1"
batch2 "k8s.io/api/batch/v1beta1"
v1 "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
rbac "k8s.io/api/rbac/v1"
storage "k8s.io/api/storage/v1"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"

apiextensionsclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
metaV1 "k8s.io/apimachinery/pkg/apis/meta/v1"
client "k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -160,7 +160,7 @@ func GetServiceListChannel(client client.Interface, nsQuery *NamespaceQuery,

// IngressListChannel is a list and error channels to Ingresss.
type IngressListChannel struct {
List chan *extensions.IngressList
List chan *networkingv1.IngressList
Error chan error
}

Expand All @@ -170,12 +170,12 @@ func GetIngressListChannel(client client.Interface, nsQuery *NamespaceQuery,
numReads int) IngressListChannel {

channel := IngressListChannel{
List: make(chan *extensions.IngressList, numReads),
List: make(chan *networkingv1.IngressList, numReads),
Error: make(chan error, numReads),
}
go func() {
list, err := client.ExtensionsV1beta1().Ingresses(nsQuery.ToRequestParam()).List(context.TODO(), api.ListEverything)
var filteredItems []extensions.Ingress
list, err := client.NetworkingV1().Ingresses(nsQuery.ToRequestParam()).List(context.TODO(), api.ListEverything)
var filteredItems []networkingv1.Ingress
for _, item := range list.Items {
if nsQuery.Matches(item.ObjectMeta.Namespace) {
filteredItems = append(filteredItems, item)
Expand Down Expand Up @@ -865,31 +865,6 @@ func GetCustomResourceDefinitionChannelV1(client apiextensionsclientset.Interfac
return channel
}

// CustomResourceDefinitionChannel is a list and error channels to CustomResourceDefinition.
type CustomResourceDefinitionChannelV1beta1 struct {
List chan *apiextensionsv1beta1.CustomResourceDefinitionList
Error chan error
}

// GetCustomResourceDefinitionChannelV1beta1 returns a pair of channels to a CustomResourceDefinition list and errors
// that both must be read numReads times.
func GetCustomResourceDefinitionChannelV1beta1(client apiextensionsclientset.Interface, numReads int) CustomResourceDefinitionChannelV1beta1 {
channel := CustomResourceDefinitionChannelV1beta1{
List: make(chan *apiextensionsv1beta1.CustomResourceDefinitionList, numReads),
Error: make(chan error, numReads),
}

go func() {
list, err := client.ApiextensionsV1beta1().CustomResourceDefinitions().List(context.TODO(), api.ListEverything)
for i := 0; i < numReads; i++ {
channel.List <- list
channel.Error <- err
}
}()

return channel
}

// ResourceQuotaListChannel is a list and error channels to ResourceQuotas.
type ResourceQuotaListChannel struct {
List chan *v1.ResourceQuotaList
Expand Down
13 changes: 0 additions & 13 deletions src/app/backend/resource/customresourcedefinition/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"

apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apiextensionsv1beta "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
"k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
apiextensionsclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -31,14 +30,12 @@ import (
"github.com/kubernetes/dashboard/src/app/backend/resource/common"
"github.com/kubernetes/dashboard/src/app/backend/resource/customresourcedefinition/types"
crdv1 "github.com/kubernetes/dashboard/src/app/backend/resource/customresourcedefinition/v1"
crdv1beta1 "github.com/kubernetes/dashboard/src/app/backend/resource/customresourcedefinition/v1beta1"
"github.com/kubernetes/dashboard/src/app/backend/resource/dataselect"
)

var (
groupName = apiextensionsv1.GroupName
v1 = apiextensionsv1.SchemeGroupVersion.Version
v1beta1 = apiextensionsv1beta.SchemeGroupVersion.Version
)

func GetExtensionsAPIVersion(client clientset.Interface) (string, error) {
Expand All @@ -65,8 +62,6 @@ func GetExtensionsAPIRestClient(client clientset.Interface) (rest.Interface, err
switch version {
case v1:
return client.ApiextensionsV1().RESTClient(), nil
case v1beta1:
return client.ApiextensionsV1beta1().RESTClient(), nil
}

return nil, errors.NewNotFound(fmt.Sprintf("unsupported extensions api version: %s", version))
Expand All @@ -81,8 +76,6 @@ func GetCustomResourceDefinitionList(client apiextensionsclientset.Interface, ds
switch version {
case v1:
return crdv1.GetCustomResourceDefinitionList(client, dsQuery)
case v1beta1:
return crdv1beta1.GetCustomResourceDefinitionList(client, dsQuery)
}

return nil, errors.NewNotFound(fmt.Sprintf("unsupported extensions api version: %s", version))
Expand All @@ -97,8 +90,6 @@ func GetCustomResourceDefinitionDetail(client apiextensionsclientset.Interface,
switch version {
case v1:
return crdv1.GetCustomResourceDefinitionDetail(client, config, name)
case v1beta1:
return crdv1beta1.GetCustomResourceDefinitionDetail(client, config, name)
}

return nil, errors.NewNotFound(fmt.Sprintf("unsupported extensions api versions: %s", version))
Expand All @@ -114,8 +105,6 @@ func GetCustomResourceObjectList(client apiextensionsclientset.Interface, config
switch version {
case v1:
return crdv1.GetCustomResourceObjectList(client, config, namespace, dsQuery, crdName)
case v1beta1:
return crdv1beta1.GetCustomResourceObjectList(client, config, namespace, dsQuery, crdName)
}

return nil, errors.NewNotFound(fmt.Sprintf("unsupported extensions api versions: %s", version))
Expand All @@ -130,8 +119,6 @@ func GetCustomResourceObjectDetail(client apiextensionsclientset.Interface, name
switch version {
case v1:
return crdv1.GetCustomResourceObjectDetail(client, namespace, config, crdName, name)
case v1beta1:
return crdv1beta1.GetCustomResourceObjectDetail(client, namespace, config, crdName, name)
}

return nil, errors.NewNotFound(fmt.Sprintf("unsupported extensions api versions: %s", version))
Expand Down

This file was deleted.

Loading

0 comments on commit 8b7e59a

Please sign in to comment.