@@ -6,10 +6,12 @@ package local
66import (
77 "context"
88
9+ openapi_v2 "github.com/google/gnostic/openapiv2"
910 authenticationv1api "k8s.io/api/authentication/v1"
1011 corev1api "k8s.io/api/core/v1"
1112 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1213 types "k8s.io/apimachinery/pkg/types"
14+ version "k8s.io/apimachinery/pkg/version"
1315 watch "k8s.io/apimachinery/pkg/watch"
1416 aplcorev1 "k8s.io/client-go/applyconfigurations/core/v1"
1517 discovery "k8s.io/client-go/discovery"
@@ -64,6 +66,7 @@ import (
6466 storagev1 "k8s.io/client-go/kubernetes/typed/storage/v1"
6567 storagev1alpha1 "k8s.io/client-go/kubernetes/typed/storage/v1alpha1"
6668 storagev1beta1 "k8s.io/client-go/kubernetes/typed/storage/v1beta1"
69+ "k8s.io/client-go/openapi"
6770 rest "k8s.io/client-go/rest"
6871)
6972
@@ -91,7 +94,7 @@ type MinCoreClient struct {
9194
9295var _ kubernetes.Interface = & MinCoreClient {}
9396
94- func (* MinCoreClient ) Discovery () discovery.DiscoveryInterface { panic ( "Not implemented" ); return nil }
97+ func (* MinCoreClient ) Discovery () discovery.DiscoveryInterface { return & MinDiscoveryClient {} }
9598func (* MinCoreClient ) AdmissionregistrationV1 () admissionregistrationv1.AdmissionregistrationV1Interface {
9699 panic ("Not implemented" )
97100 return nil
@@ -172,6 +175,11 @@ func (*MinCoreClient) CoordinationV1() coordinationv1.CoordinationV1Interface {
172175 return nil
173176}
174177func (c * MinCoreClient ) CoreV1 () corev1.CoreV1Interface {
178+ if c .client == nil {
179+ // To be used only while releasing packages where we do not expect nil client to be used
180+ // MinServiceAccount will mock necessary bits
181+ return & MinCoreV1Client {nil , c .localSecrets , c .localConfigMaps }
182+ }
175183 return & MinCoreV1Client {c .client .CoreV1 (), c .localSecrets , c .localConfigMaps }
176184}
177185func (* MinCoreClient ) DiscoveryV1 () discoveryv1.DiscoveryV1Interface {
@@ -324,6 +332,10 @@ func (*MinCoreV1Client) Services(namespace string) corev1.ServiceInterface {
324332 return nil
325333}
326334func (c * MinCoreV1Client ) ServiceAccounts (namespace string ) corev1.ServiceAccountInterface {
335+ if c .client == nil {
336+ // To handle package release scenarios with DownwardsAPI
337+ return & ServiceAccounts {namespace , nil }
338+ }
327339 return & ServiceAccounts {namespace , c .client .ServiceAccounts (namespace )}
328340}
329341
@@ -452,6 +464,10 @@ func (*ServiceAccounts) DeleteCollection(ctx context.Context, opts metav1.Delete
452464 return nil
453465}
454466func (sa * ServiceAccounts ) Get (ctx context.Context , name string , opts metav1.GetOptions ) (* corev1api.ServiceAccount , error ) {
467+ if sa .client == nil {
468+ // To handle package release scenarios with DownwardsAPI
469+ return & corev1api.ServiceAccount {}, nil
470+ }
455471 return sa .client .Get (ctx , name , opts )
456472}
457473func (* ServiceAccounts ) List (ctx context.Context , opts metav1.ListOptions ) (* corev1api.ServiceAccountList , error ) {
@@ -471,5 +487,39 @@ func (*ServiceAccounts) Apply(ctx context.Context, serviceAccount *aplcorev1.Ser
471487 return nil , nil
472488}
473489func (sa * ServiceAccounts ) CreateToken (ctx context.Context , serviceAccountName string , tokenRequest * authenticationv1api.TokenRequest , opts metav1.CreateOptions ) (* authenticationv1api.TokenRequest , error ) {
490+ if sa .client == nil {
491+ // To handle package release scenarios with DownwardsAPI
492+ return & authenticationv1api.TokenRequest {}, nil
493+ }
474494 return sa .client .CreateToken (ctx , serviceAccountName , tokenRequest , opts )
475495}
496+
497+ // Minimum required values to
498+ type MinDiscoveryClient struct {}
499+
500+ var _ discovery.DiscoveryInterface = & MinDiscoveryClient {}
501+
502+ func (* MinDiscoveryClient ) ServerVersion () (* version.Info , error ) {
503+ return & version.Info {Major : "1" , Minor : "30.0-invalid" , GitVersion : "1.30.0-invalid" }, nil
504+ }
505+
506+ func (* MinDiscoveryClient ) ServerGroups () (* metav1.APIGroupList , error ) {
507+ return & metav1.APIGroupList {}, nil
508+ }
509+
510+ func (* MinDiscoveryClient ) RESTClient () rest.Interface { panic ("Not implemented" ) }
511+ func (* MinDiscoveryClient ) ServerResourcesForGroupVersion (groupVersion string ) (* metav1.APIResourceList , error ) {
512+ panic ("Not implemented" )
513+ }
514+ func (* MinDiscoveryClient ) ServerGroupsAndResources () ([]* metav1.APIGroup , []* metav1.APIResourceList , error ) {
515+ panic ("Not implemented" )
516+ }
517+ func (* MinDiscoveryClient ) ServerPreferredResources () ([]* metav1.APIResourceList , error ) {
518+ panic ("Not implemented" )
519+ }
520+ func (* MinDiscoveryClient ) ServerPreferredNamespacedResources () ([]* metav1.APIResourceList , error ) {
521+ panic ("Not implemented" )
522+ }
523+ func (* MinDiscoveryClient ) OpenAPISchema () (* openapi_v2.Document , error ) { panic ("Not implemented" ) }
524+ func (* MinDiscoveryClient ) OpenAPIV3 () openapi.Client { panic ("Not implemented" ) }
525+ func (* MinDiscoveryClient ) WithLegacy () discovery.DiscoveryInterface { panic ("Not implemented" ) }
0 commit comments