This repository was archived by the owner on Dec 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 750
877 allow controller to use token #885
Merged
andresmgot
merged 15 commits into
vmware-archive:master
from
jamding:877-allow-controller-to-use-token
Aug 17, 2018
Merged
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6ed2ef2
adding readme
c1fdac4
Support setting env variable for bearer token
2642a91
Revert "adding readme"
jamding 468bb63
formatting
jamding abb03b4
Delete glide.yaml
89b32fd
Remove description for CRDs (#887)
andresmgot 9a68b31
Renaming GetOverriddenClientConfig to GetInClusterConfig, removing re…
jamding fa18f16
adding readme
dc94e65
Support setting env variable for bearer token
4005804
Revert "adding readme"
jamding 8e71661
formatting
jamding 57d518d
Renaming GetOverriddenClientConfig to GetInClusterConfig, removing re…
jamding be459ae
Merge branch '877-allow-controller-to-use-token' of github.com:jamdin…
jamding 12cdbed
Adding docs for KUBELESS_TOKEN_FILE_PATH
jamding 3805e72
Fix format
andresmgot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ import ( | |
kubelessApi "github.com/kubeless/kubeless/pkg/apis/kubeless/v1beta1" | ||
"github.com/kubeless/kubeless/pkg/langruntime" | ||
"github.com/sirupsen/logrus" | ||
"io/ioutil" | ||
batchv1 "k8s.io/api/batch/v1" | ||
"k8s.io/api/core/v1" | ||
"k8s.io/api/extensions/v1beta1" | ||
|
@@ -40,6 +41,7 @@ import ( | |
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/apimachinery/pkg/util/intstr" | ||
"k8s.io/client-go/kubernetes" | ||
"k8s.io/client-go/rest" | ||
) | ||
|
||
// GetFunctionPort returns the port for a function service | ||
|
@@ -760,6 +762,23 @@ func GetOwnerReference(kind, apiVersion, name string, uid types.UID) ([]metav1.O | |
}, nil | ||
} | ||
|
||
// GetControllerRestClientConfig returns necessary Config object to authenticate k8s clients if env variable is set | ||
func GetOverriddenClientConfig() (*rest.Config, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd call this |
||
config, err := rest.InClusterConfig() | ||
|
||
tokenFile := os.Getenv("KUBELESS_TOKEN_FILE_PATH") | ||
if len(tokenFile) == 0 { | ||
return config, err | ||
} | ||
tokenBytes, err := ioutil.ReadFile(tokenFile) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to read file containing oauth token: %s", err) | ||
} | ||
config.BearerToken = string(tokenBytes) | ||
|
||
return config, nil | ||
} | ||
|
||
func getConfigLocation(apiExtensionsClientset clientsetAPIExtensions.Interface) (ConfigLocation, error) { | ||
configLocation := ConfigLocation{} | ||
controllerNamespace := os.Getenv("KUBELESS_NAMESPACE") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
the error could be related to something else, it's better to avoid having to retrieve the config twice. In fact if
KUBELESS_TOKEN_FILE_PATH
is not set you are already returning the result ofrest.InClusterConfig()
so you don't need thisif
block.