Skip to content

Commit 4821a0d

Browse files
committed
Add partial support for DownwardsAPI with kctrl package release
Signed-off-by: Soumik Majumder <[email protected]>
1 parent 35abe96 commit 4821a0d

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

cli/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/cppforlife/color v1.9.1-0.20200716202919-6706ac40b835
88
github.com/cppforlife/go-cli-ui v0.0.0-20220520125801-e45d9169a663
99
github.com/getkin/kin-openapi v0.81.0
10+
github.com/google/gnostic v0.5.7-v3refs
1011
github.com/google/go-containerregistry v0.13.0
1112
github.com/k14s/difflib v0.0.0-20201117154628-0c031775bf57
1213
github.com/mitchellh/go-wordwrap v1.0.1
@@ -45,7 +46,6 @@ require (
4546
github.com/gogo/protobuf v1.3.2 // indirect
4647
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
4748
github.com/golang/protobuf v1.5.2 // indirect
48-
github.com/google/gnostic v0.5.7-v3refs // indirect
4949
github.com/google/go-cmp v0.5.9 // indirect
5050
github.com/google/gofuzz v1.2.0 // indirect
5151
github.com/google/uuid v1.2.0 // indirect

cli/pkg/kctrl/cmd/app/release/app_spec_builder.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func (b *AppSpecBuilder) Build() (kcv1alpha1.AppSpec, error) {
5959
},
6060
},
6161
Spec: kcv1alpha1.AppSpec{
62+
ServiceAccountName: "fake-sa",
6263
Fetch: []kcv1alpha1.AppFetch{
6364
{
6465
// To be replaced by local fetch

cli/pkg/kctrl/local/min_core_client.go

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ package local
66
import (
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

9295
var _ kubernetes.Interface = &MinCoreClient{}
9396

94-
func (*MinCoreClient) Discovery() discovery.DiscoveryInterface { panic("Not implemented"); return nil }
97+
func (*MinCoreClient) Discovery() discovery.DiscoveryInterface { return &MinDiscoveryClient{} }
9598
func (*MinCoreClient) AdmissionregistrationV1() admissionregistrationv1.AdmissionregistrationV1Interface {
9699
panic("Not implemented")
97100
return nil
@@ -172,6 +175,11 @@ func (*MinCoreClient) CoordinationV1() coordinationv1.CoordinationV1Interface {
172175
return nil
173176
}
174177
func (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
}
177185
func (*MinCoreClient) DiscoveryV1() discoveryv1.DiscoveryV1Interface {
@@ -324,6 +332,10 @@ func (*MinCoreV1Client) Services(namespace string) corev1.ServiceInterface {
324332
return nil
325333
}
326334
func (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
}
454466
func (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
}
457473
func (*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
}
473489
func (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

Comments
 (0)