From 35112c6ee7889213770e8e9adb9f0e0fd4808b07 Mon Sep 17 00:00:00 2001 From: orangedeng Date: Tue, 11 Jun 2019 14:54:16 +0800 Subject: [PATCH] Introduce APIService resource to Rancher --- apis/cluster.cattle.io/v3/schema/schema.go | 12 +++- config/context.go | 69 ++++++++++++++-------- main.go | 6 ++ 3 files changed, 63 insertions(+), 24 deletions(-) diff --git a/apis/cluster.cattle.io/v3/schema/schema.go b/apis/cluster.cattle.io/v3/schema/schema.go index d70b6c14..cc7097fd 100644 --- a/apis/cluster.cattle.io/v3/schema/schema.go +++ b/apis/cluster.cattle.io/v3/schema/schema.go @@ -10,6 +10,7 @@ import ( "github.com/rancher/types/factory" v1 "k8s.io/api/core/v1" storagev1 "k8s.io/api/storage/v1" + apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" ) var ( @@ -25,7 +26,8 @@ var ( Init(namespaceTypes). Init(persistentVolumeTypes). Init(storageClassTypes). - Init(tokens) + Init(tokens). + Init(apiServiceTypes) ) func namespaceTypes(schemas *types.Schemas) *types.Schemas { @@ -130,3 +132,11 @@ func tokens(schemas *types.Schemas) *types.Schemas { schema.ResourceMethods = []string{} }) } + +func apiServiceTypes(Schemas *types.Schemas) *types.Schemas { + return Schemas. + AddMapperForType(&Version, apiregistrationv1.APIService{}, + &m.Embed{Field: "status"}, + ). + MustImport(&Version, apiregistrationv1.APIService{}) +} diff --git a/config/context.go b/config/context.go index 5b602534..9417a636 100644 --- a/config/context.go +++ b/config/context.go @@ -9,6 +9,7 @@ import ( "github.com/rancher/norman/signal" "github.com/rancher/norman/store/proxy" "github.com/rancher/norman/types" + apiregistrationv1 "github.com/rancher/types/apis/apiregistration.k8s.io/v1" appsv1beta2 "github.com/rancher/types/apis/apps/v1beta2" autoscaling "github.com/rancher/types/apis/autoscaling/v2beta2" batchv1 "github.com/rancher/types/apis/batch/v1" @@ -179,22 +180,24 @@ type UserContext struct { APIExtClient clientset.Interface K8sClient kubernetes.Interface - Apps appsv1beta2.Interface - Autoscaling autoscaling.Interface - Project projectv3.Interface - Core corev1.Interface - RBAC rbacv1.Interface - Extensions extv1beta1.Interface - BatchV1 batchv1.Interface - BatchV1Beta1 batchv1beta1.Interface - Networking knetworkingv1.Interface - Monitoring monitoringv1.Interface - Cluster clusterv3.Interface - Istio istiov1alpha3.Interface + APIAggregation apiregistrationv1.Interface + Apps appsv1beta2.Interface + Autoscaling autoscaling.Interface + Project projectv3.Interface + Core corev1.Interface + RBAC rbacv1.Interface + Extensions extv1beta1.Interface + BatchV1 batchv1.Interface + BatchV1Beta1 batchv1beta1.Interface + Networking knetworkingv1.Interface + Monitoring monitoringv1.Interface + Cluster clusterv3.Interface + Istio istiov1alpha3.Interface } func (w *UserContext) controllers() []controller.Starter { return []controller.Starter{ + w.APIAggregation, w.Apps, w.Project, w.Core, @@ -237,21 +240,23 @@ type UserOnlyContext struct { UnversionedClient rest.Interface K8sClient kubernetes.Interface - Apps appsv1beta2.Interface - Autoscaling autoscaling.Interface - Project projectv3.Interface - Core corev1.Interface - RBAC rbacv1.Interface - Extensions extv1beta1.Interface - BatchV1 batchv1.Interface - BatchV1Beta1 batchv1beta1.Interface - Monitoring monitoringv1.Interface - Cluster clusterv3.Interface - Istio istiov1alpha3.Interface + APIRegistration apiregistrationv1.Interface + Apps appsv1beta2.Interface + Autoscaling autoscaling.Interface + Project projectv3.Interface + Core corev1.Interface + RBAC rbacv1.Interface + Extensions extv1beta1.Interface + BatchV1 batchv1.Interface + BatchV1Beta1 batchv1beta1.Interface + Monitoring monitoringv1.Interface + Cluster clusterv3.Interface + Istio istiov1alpha3.Interface } func (w *UserOnlyContext) controllers() []controller.Starter { return []controller.Starter{ + w.APIRegistration, w.Apps, w.Project, w.Core, @@ -407,6 +412,10 @@ func NewUserContext(scaledContext *ScaledContext, config rest.Config, clusterNam } context.Monitoring, err = monitoringv1.NewForConfig(config) + if err != nil { + return nil, err + } + context.Cluster, err = clusterv3.NewForConfig(config) if err != nil { return nil, err @@ -417,6 +426,11 @@ func NewUserContext(scaledContext *ScaledContext, config rest.Config, clusterNam return nil, err } + context.APIAggregation, err = apiregistrationv1.NewForConfig(config) + if err != nil { + return nil, err + } + dynamicConfig := config if dynamicConfig.NegotiatedSerializer == nil { dynamicConfig.NegotiatedSerializer = dynamic.NegotiatedSerializer @@ -501,6 +515,10 @@ func NewUserOnlyContext(config rest.Config) (*UserOnlyContext, error) { } context.Monitoring, err = monitoringv1.NewForConfig(config) + if err != nil { + return nil, err + } + context.Cluster, err = clusterv3.NewForConfig(config) if err != nil { return nil, err @@ -511,6 +529,11 @@ func NewUserOnlyContext(config rest.Config) (*UserOnlyContext, error) { return nil, err } + context.APIRegistration, err = apiregistrationv1.NewForConfig(config) + if err != nil { + return nil, err + } + dynamicConfig := config if dynamicConfig.NegotiatedSerializer == nil { dynamicConfig.NegotiatedSerializer = dynamic.NegotiatedSerializer diff --git a/main.go b/main.go index ef84f8c1..5baf60c1 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,7 @@ import ( knetworkingv1 "k8s.io/api/networking/v1" rbacv1 "k8s.io/api/rbac/v1" k8sschema "k8s.io/apimachinery/pkg/runtime/schema" + apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1" ) func main() { @@ -104,4 +105,9 @@ func main() { }, []interface{}{}, ) + generator.GenerateNativeTypes(apiregistrationv1.SchemeGroupVersion, + []interface{}{}, []interface{}{ + apiregistrationv1.APIService{}, + }, + ) }