-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
Signed-off-by: Mustafa Abdelrahman <mustafa.abdelrahman@zalando.de>
@@ -83,6 +87,21 @@ func CreateUnified() (Interface, error) { | |||
return client, nil | |||
} | |||
|
|||
// CreateUnified returns the unified client | |||
func CreateUnifiedWithOptions(opts *Options) (Interface, error) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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{}) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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"}) |
There was a problem hiding this comment.
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
Closing this since it could be resolved by using the right loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
configOverrides := &clientcmd.ConfigOverrides{}
kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides)
config, err := kubeConfig.ClientConfig()
# error handling
client, err := rgclient.NewClientset(kubeConfig)
# error handling |
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