Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update client to use BearerTokenFile when needed #15

Closed
wants to merge 3 commits into from

Conversation

MustafaSaber
Copy link

@MustafaSaber MustafaSaber commented Oct 4, 2023

With this PR we should be able to lunch the client with different Options or none, it tries to resemble zalando/skipper#2590 so requests could be authorized with tokens outside clusters.

Without this PR I get 2023/10/04 17:55:21 Failed to get Ingress list: Unauthorized in the example, could hack around and try to use /var/run/secrets/kubernetes.io/serviceaccount/token but this also didn't work

Signed-off-by: Mustafa Abdelrahman <mustafa.abdelrahman@zalando.de>
cli/rg-client-test/main.go Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
@@ -83,6 +87,21 @@ func CreateUnified() (Interface, error) {
return client, nil
}

// CreateUnified returns the unified client
func CreateUnifiedWithOptions(opts *Options) (Interface, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to create client via CreateUnified() and then modify its rest.Config?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively we can also consider using functional options, see https://golang.cafe/blog/golang-functional-options-pattern.html

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it returns the clientset at this level we only can call resources.

Signed-off-by: Mustafa Abdelrahman <mustafa.abdelrahman@zalando.de>
Signed-off-by: Mustafa Abdelrahman <mustafa.abdelrahman@zalando.de>
if err != nil {
log.Fatalf("Failed to create unified RouteGroup client: %v", err)
}
log.Println("have cli")

// example kubernetes.Interface access
ings, err := cli.ExtensionsV1beta1().Ingresses("").List(context.TODO(), metav1.ListOptions{})
//ings, err := cli.NetworkingV1().Ingress("").List(context.TODO(), metav1.ListOptions{})
// ings, err := cli.ExtensionsV1beta1().Ingresses("").List(context.TODO(), metav1.ListOptions{})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop this comment

@@ -12,17 +12,22 @@ import (
)

func main() {
cli, err := rgclient.CreateUnified()
cli, err := rgclient.CreateUnifiedWithOptions(&rgclient.Options{TokenFile: "/tmp/k8s_token"})
// cli, err := rgclient.CreateUnified()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop this comment

@@ -12,17 +12,22 @@ import (
)

func main() {
cli, err := rgclient.CreateUnified()
cli, err := rgclient.CreateUnifiedWithOptions(&rgclient.Options{TokenFile: "/tmp/k8s_token"})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you want to specify a const for this and I don't see how a fixed file can help in a test as you need to write the valid token into the file somehow

@MustafaSaber
Copy link
Author

Closing this since it could be resolved by using the right $KUBECONFIG and

loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
configOverrides := &clientcmd.ConfigOverrides{}
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides)
config, err := kubeConfig.ClientConfig()
# error handling
client, err := rgclient.NewClientset(kubeConfig)
# error handling

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants