Skip to content

Commit

Permalink
Support a default context in the kubecfg template
Browse files Browse the repository at this point in the history
  • Loading branch information
Nic Cope committed Mar 12, 2018
1 parent 73a4bc7 commit fc57fef
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions kuberos.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ func populateUser(cfg *api.Config, p *extractor.OIDCAuthenticationParams) api.Co
c.AuthInfos = make(map[string]*api.AuthInfo)
c.Clusters = make(map[string]*api.Cluster)
c.Contexts = make(map[string]*api.Context)
c.CurrentContext = cfg.CurrentContext
c.AuthInfos[p.Username] = &api.AuthInfo{
AuthProvider: &api.AuthProviderConfig{
Name: templateAuthProvider,
Expand Down
43 changes: 43 additions & 0 deletions kuberos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,49 @@ func TestPopulateUser(t *testing.T) {
},
},
},
{
name: "MultiClusterWithContext",
cfg: &api.Config{
Clusters: map[string]*api.Cluster{
"a": &api.Cluster{Server: "https://example.org", CertificateAuthorityData: []byte("PAM")},
"b": &api.Cluster{Server: "https://example.net", CertificateAuthorityData: []byte("PAM")},
},
CurrentContext: "a",
},
params: &extractor.OIDCAuthenticationParams{
Username: "[email protected]",
ClientID: "id",
ClientSecret: "secret",
IDToken: "token",
RefreshToken: "refresh",
IssuerURL: "https://example.org",
},
want: api.Config{
Clusters: map[string]*api.Cluster{
"a": &api.Cluster{Server: "https://example.org", CertificateAuthorityData: []byte("PAM")},
"b": &api.Cluster{Server: "https://example.net", CertificateAuthorityData: []byte("PAM")},
},
Contexts: map[string]*api.Context{
"a": &api.Context{AuthInfo: "[email protected]", Cluster: "a"},
"b": &api.Context{AuthInfo: "[email protected]", Cluster: "b"},
},
AuthInfos: map[string]*api.AuthInfo{
"[email protected]": &api.AuthInfo{
AuthProvider: &api.AuthProviderConfig{
Name: templateAuthProvider,
Config: map[string]string{
templateOIDCClientID: "id",
templateOIDCClientSecret: "secret",
templateOIDCIDToken: "token",
templateOIDCRefreshToken: "refresh",
templateOIDCIssuer: "https://example.org",
},
},
},
},
CurrentContext: "a",
},
},
}

for _, tt := range cases {
Expand Down

0 comments on commit fc57fef

Please sign in to comment.