Merge pull request #59428 from mikedanese/id-defaults

Automatic merge from submit-queue (batch tested with PRs 59052, 59157, 59428, 59949, 60151). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

svcacct: default expiration of TokenRequest

* default expiration seconds to 1 hour

```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2018-02-21 16:55:39 -08:00 committed by GitHub
commit 814615aa84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 0 deletions

View File

@ -145,6 +145,7 @@ func TestDefaulting(t *testing.T) {
{Group: "storage.k8s.io", Version: "v1beta1", Kind: "StorageClassList"}: {},
{Group: "storage.k8s.io", Version: "v1", Kind: "StorageClass"}: {},
{Group: "storage.k8s.io", Version: "v1", Kind: "StorageClassList"}: {},
{Group: "authentication.k8s.io", Version: "v1", Kind: "TokenRequest"}: {},
}
f := fuzz.New().NilChance(.5).NumElements(1, 1).RandSource(rand.NewSource(1))

View File

@ -17,9 +17,17 @@ limitations under the License.
package v1
import (
authenticationv1 "k8s.io/api/authentication/v1"
"k8s.io/apimachinery/pkg/runtime"
)
func addDefaultingFuncs(scheme *runtime.Scheme) error {
return RegisterDefaults(scheme)
}
func SetDefaults_TokenRequestSpec(obj *authenticationv1.TokenRequestSpec) {
if obj.ExpirationSeconds == nil {
hour := int64(60 * 60)
obj.ExpirationSeconds = &hour
}
}

View File

@ -21,6 +21,7 @@ limitations under the License.
package v1
import (
v1 "k8s.io/api/authentication/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
)
@ -28,5 +29,10 @@ import (
// Public to allow building arbitrary schemes.
// All generated defaulters are covering - they call all nested defaulters.
func RegisterDefaults(scheme *runtime.Scheme) error {
scheme.AddTypeDefaultingFunc(&v1.TokenRequest{}, func(obj interface{}) { SetObjectDefaults_TokenRequest(obj.(*v1.TokenRequest)) })
return nil
}
func SetObjectDefaults_TokenRequest(in *v1.TokenRequest) {
SetDefaults_TokenRequestSpec(&in.Spec)
}