mirror of
https://github.com/kubernetes/client-go.git
synced 2025-07-17 16:52:22 +00:00
client-go: promote exec plugin support to beta
Kubernetes-commit: 0a9164e73aedd898a535a64fcc992d3e50002d61
This commit is contained in:
parent
f58a8f4fd0
commit
c61cf26da4
@ -38,6 +38,7 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/runtime/serializer"
|
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||||
"k8s.io/client-go/pkg/apis/clientauthentication"
|
"k8s.io/client-go/pkg/apis/clientauthentication"
|
||||||
"k8s.io/client-go/pkg/apis/clientauthentication/v1alpha1"
|
"k8s.io/client-go/pkg/apis/clientauthentication/v1alpha1"
|
||||||
|
"k8s.io/client-go/pkg/apis/clientauthentication/v1beta1"
|
||||||
"k8s.io/client-go/tools/clientcmd/api"
|
"k8s.io/client-go/tools/clientcmd/api"
|
||||||
"k8s.io/client-go/transport"
|
"k8s.io/client-go/transport"
|
||||||
"k8s.io/client-go/util/connrotation"
|
"k8s.io/client-go/util/connrotation"
|
||||||
@ -51,6 +52,7 @@ var codecs = serializer.NewCodecFactory(scheme)
|
|||||||
func init() {
|
func init() {
|
||||||
v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"})
|
v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"})
|
||||||
v1alpha1.AddToScheme(scheme)
|
v1alpha1.AddToScheme(scheme)
|
||||||
|
v1beta1.AddToScheme(scheme)
|
||||||
clientauthentication.AddToScheme(scheme)
|
clientauthentication.AddToScheme(scheme)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,6 +63,7 @@ var (
|
|||||||
// The list of API versions we accept.
|
// The list of API versions we accept.
|
||||||
apiVersions = map[string]schema.GroupVersion{
|
apiVersions = map[string]schema.GroupVersion{
|
||||||
v1alpha1.SchemeGroupVersion.String(): v1alpha1.SchemeGroupVersion,
|
v1alpha1.SchemeGroupVersion.String(): v1alpha1.SchemeGroupVersion,
|
||||||
|
v1beta1.SchemeGroupVersion.String(): v1beta1.SchemeGroupVersion,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -294,13 +297,18 @@ func (a *Authenticator) refreshCredsLocked(r *clientauthentication.Response) err
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
env := append(a.environ(), a.env...)
|
||||||
|
if a.group == v1alpha1.SchemeGroupVersion {
|
||||||
|
// Input spec disabled for beta due to lack of use. Possibly re-enable this later if
|
||||||
|
// someone wants it back.
|
||||||
|
//
|
||||||
|
// See: https://github.com/kubernetes/kubernetes/issues/61796
|
||||||
data, err := runtime.Encode(codecs.LegacyCodec(a.group), cred)
|
data, err := runtime.Encode(codecs.LegacyCodec(a.group), cred)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("encode ExecCredentials: %v", err)
|
return fmt.Errorf("encode ExecCredentials: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
env := append(a.environ(), a.env...)
|
|
||||||
env = append(env, fmt.Sprintf("%s=%s", execInfoEnv, data))
|
env = append(env, fmt.Sprintf("%s=%s", execInfoEnv, data))
|
||||||
|
}
|
||||||
|
|
||||||
stdout := &bytes.Buffer{}
|
stdout := &bytes.Buffer{}
|
||||||
cmd := exec.Command(a.cmd, a.args...)
|
cmd := exec.Command(a.cmd, a.args...)
|
||||||
|
@ -380,6 +380,72 @@ func TestRefreshCreds(t *testing.T) {
|
|||||||
}`, certData),
|
}`, certData),
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "beta-basic-request",
|
||||||
|
config: api.ExecConfig{
|
||||||
|
APIVersion: "client.authentication.k8s.io/v1beta1",
|
||||||
|
},
|
||||||
|
output: `{
|
||||||
|
"kind": "ExecCredential",
|
||||||
|
"apiVersion": "client.authentication.k8s.io/v1beta1",
|
||||||
|
"status": {
|
||||||
|
"token": "foo-bar"
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
wantCreds: credentials{token: "foo-bar"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "beta-expiry",
|
||||||
|
config: api.ExecConfig{
|
||||||
|
APIVersion: "client.authentication.k8s.io/v1beta1",
|
||||||
|
},
|
||||||
|
output: `{
|
||||||
|
"kind": "ExecCredential",
|
||||||
|
"apiVersion": "client.authentication.k8s.io/v1beta1",
|
||||||
|
"status": {
|
||||||
|
"token": "foo-bar",
|
||||||
|
"expirationTimestamp": "2006-01-02T15:04:05Z"
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
wantExpiry: time.Date(2006, 01, 02, 15, 04, 05, 0, time.UTC),
|
||||||
|
wantCreds: credentials{token: "foo-bar"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "beta-no-group-version",
|
||||||
|
config: api.ExecConfig{
|
||||||
|
APIVersion: "client.authentication.k8s.io/v1beta1",
|
||||||
|
},
|
||||||
|
output: `{
|
||||||
|
"kind": "ExecCredential",
|
||||||
|
"status": {
|
||||||
|
"token": "foo-bar"
|
||||||
|
}
|
||||||
|
}`,
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "beta-no-status",
|
||||||
|
config: api.ExecConfig{
|
||||||
|
APIVersion: "client.authentication.k8s.io/v1beta1",
|
||||||
|
},
|
||||||
|
output: `{
|
||||||
|
"kind": "ExecCredential",
|
||||||
|
"apiVersion":"client.authentication.k8s.io/v1beta1"
|
||||||
|
}`,
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "beta-no-token",
|
||||||
|
config: api.ExecConfig{
|
||||||
|
APIVersion: "client.authentication.k8s.io/v1beta1",
|
||||||
|
},
|
||||||
|
output: `{
|
||||||
|
"kind": "ExecCredential",
|
||||||
|
"apiVersion":"client.authentication.k8s.io/v1beta1",
|
||||||
|
"status": {}
|
||||||
|
}`,
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
@ -420,6 +486,13 @@ func TestRefreshCreds(t *testing.T) {
|
|||||||
t.Errorf("expected expiry %v got %v", test.wantExpiry, a.exp)
|
t.Errorf("expected expiry %v got %v", test.wantExpiry, a.exp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if test.wantInput == "" {
|
||||||
|
if got := strings.TrimSpace(stderr.String()); got != "" {
|
||||||
|
t.Errorf("expected no input parameters, got %q", got)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
compJSON(t, stderr.Bytes(), []byte(test.wantInput))
|
compJSON(t, stderr.Bytes(), []byte(test.wantInput))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user