k8s.io/kubernetes@v1.29.3/test/e2e/apimachinery/storage_version.go (about)

     1  /*
     2  Copyright 2020 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package apimachinery
    18  
    19  import (
    20  	"context"
    21  	"time"
    22  
    23  	apiserverinternalv1alpha1 "k8s.io/api/apiserverinternal/v1alpha1"
    24  	apierrors "k8s.io/apimachinery/pkg/api/errors"
    25  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    26  	"k8s.io/apimachinery/pkg/util/wait"
    27  	"k8s.io/kubernetes/test/e2e/feature"
    28  	"k8s.io/kubernetes/test/e2e/framework"
    29  	admissionapi "k8s.io/pod-security-admission/api"
    30  
    31  	"github.com/onsi/ginkgo/v2"
    32  )
    33  
    34  const (
    35  	svName     = "storageversion.e2e.test.foos"
    36  	idNonExist = "id-non-exist"
    37  )
    38  
    39  // This test requires that --feature-gates=APIServerIdentity=true,StorageVersionAPI=true be set on the apiserver and the controller manager
    40  var _ = SIGDescribe("StorageVersion resources", feature.StorageVersionAPI, func() {
    41  	f := framework.NewDefaultFramework("storage-version")
    42  	f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged
    43  
    44  	ginkgo.It("storage version with non-existing id should be GC'ed", func(ctx context.Context) {
    45  		client := f.ClientSet
    46  		sv := &apiserverinternalv1alpha1.StorageVersion{
    47  			ObjectMeta: metav1.ObjectMeta{
    48  				GenerateName: svName,
    49  			},
    50  		}
    51  		createdSV, err := client.InternalV1alpha1().StorageVersions().Create(ctx, sv, metav1.CreateOptions{})
    52  		framework.ExpectNoError(err, "creating storage version")
    53  
    54  		// update the created sv with server storage version
    55  		version := "v1"
    56  		createdSV.Status = apiserverinternalv1alpha1.StorageVersionStatus{
    57  			StorageVersions: []apiserverinternalv1alpha1.ServerStorageVersion{
    58  				{
    59  					APIServerID:       idNonExist,
    60  					EncodingVersion:   version,
    61  					DecodableVersions: []string{version},
    62  				},
    63  			},
    64  			CommonEncodingVersion: &version,
    65  		}
    66  		_, err = client.InternalV1alpha1().StorageVersions().UpdateStatus(
    67  			ctx, createdSV, metav1.UpdateOptions{})
    68  		framework.ExpectNoError(err, "updating storage version")
    69  
    70  		// wait for sv to be GC'ed
    71  		framework.Logf("Waiting for storage version %v to be garbage collected", createdSV.Name)
    72  		err = wait.PollImmediate(100*time.Millisecond, wait.ForeverTestTimeout, func() (bool, error) {
    73  			_, err := client.InternalV1alpha1().StorageVersions().Get(
    74  				ctx, createdSV.Name, metav1.GetOptions{})
    75  			if apierrors.IsNotFound(err) {
    76  				return true, nil
    77  			}
    78  			if err != nil {
    79  				return false, err
    80  			}
    81  			framework.Logf("The storage version %v hasn't been garbage collected yet. Retrying", createdSV.Name)
    82  			return false, nil
    83  		})
    84  		framework.ExpectNoError(err, "garbage-collecting storage version")
    85  	})
    86  })