rest.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. Copyright 2019 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package replicaset
  14. import (
  15. "fmt"
  16. apps "k8s.io/api/apps/v1"
  17. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  18. clientset "k8s.io/client-go/kubernetes"
  19. deploymentutil "k8s.io/kubernetes/pkg/controller/deployment/util"
  20. "k8s.io/kubernetes/test/e2e/framework"
  21. e2elog "k8s.io/kubernetes/test/e2e/framework/log"
  22. testutils "k8s.io/kubernetes/test/utils"
  23. )
  24. // UpdateReplicaSetWithRetries updates replicaset template with retries.
  25. func UpdateReplicaSetWithRetries(c clientset.Interface, namespace, name string, applyUpdate testutils.UpdateReplicaSetFunc) (*apps.ReplicaSet, error) {
  26. return testutils.UpdateReplicaSetWithRetries(c, namespace, name, applyUpdate, e2elog.Logf, framework.Poll, framework.PollShortTimeout)
  27. }
  28. // CheckNewRSAnnotations check if the new RS's annotation is as expected
  29. func CheckNewRSAnnotations(c clientset.Interface, ns, deploymentName string, expectedAnnotations map[string]string) error {
  30. deployment, err := c.AppsV1().Deployments(ns).Get(deploymentName, metav1.GetOptions{})
  31. if err != nil {
  32. return err
  33. }
  34. newRS, err := deploymentutil.GetNewReplicaSet(deployment, c.AppsV1())
  35. if err != nil {
  36. return err
  37. }
  38. for k, v := range expectedAnnotations {
  39. // Skip checking revision annotations
  40. if k != deploymentutil.RevisionAnnotation && v != newRS.Annotations[k] {
  41. return fmt.Errorf("Expected new RS annotations = %+v, got %+v", expectedAnnotations, newRS.Annotations)
  42. }
  43. }
  44. return nil
  45. }