mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 03:03:59 +00:00
Merge pull request #26654 from janetkuo/e2e-deployment-list-rs
Automatic merge from submit-queue List RSes once when getting old/new RSes in deployment e2e tests Ref #26509 []()
This commit is contained in:
commit
cae939b81c
@ -1922,12 +1922,9 @@ func (dd *DeploymentDescriber) Describe(namespace, name string, describerSetting
|
|||||||
ru := d.Spec.Strategy.RollingUpdate
|
ru := d.Spec.Strategy.RollingUpdate
|
||||||
fmt.Fprintf(out, "RollingUpdateStrategy:\t%s max unavailable, %s max surge\n", ru.MaxUnavailable.String(), ru.MaxSurge.String())
|
fmt.Fprintf(out, "RollingUpdateStrategy:\t%s max unavailable, %s max surge\n", ru.MaxUnavailable.String(), ru.MaxSurge.String())
|
||||||
}
|
}
|
||||||
oldRSs, _, err := deploymentutil.GetOldReplicaSets(d, dd)
|
oldRSs, _, newRS, err := deploymentutil.GetAllReplicaSets(d, dd)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
fmt.Fprintf(out, "OldReplicaSets:\t%s\n", printReplicaSetsByLabels(oldRSs))
|
fmt.Fprintf(out, "OldReplicaSets:\t%s\n", printReplicaSetsByLabels(oldRSs))
|
||||||
}
|
|
||||||
newRS, err := deploymentutil.GetNewReplicaSet(d, dd)
|
|
||||||
if err == nil {
|
|
||||||
var newRSs []*extensions.ReplicaSet
|
var newRSs []*extensions.ReplicaSet
|
||||||
if newRS != nil {
|
if newRS != nil {
|
||||||
newRSs = append(newRSs, newRS)
|
newRSs = append(newRSs, newRS)
|
||||||
|
@ -66,13 +66,9 @@ func (h *DeploymentHistoryViewer) History(namespace, name string) (HistoryInfo,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return historyInfo, fmt.Errorf("failed to retrieve deployment %s: %v", name, err)
|
return historyInfo, fmt.Errorf("failed to retrieve deployment %s: %v", name, err)
|
||||||
}
|
}
|
||||||
_, allOldRSs, err := deploymentutil.GetOldReplicaSets(deployment, h.c)
|
_, allOldRSs, newRS, err := deploymentutil.GetAllReplicaSets(deployment, h.c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return historyInfo, fmt.Errorf("failed to retrieve old replica sets from deployment %s: %v", name, err)
|
return historyInfo, fmt.Errorf("failed to retrieve replica sets from deployment %s: %v", name, err)
|
||||||
}
|
|
||||||
newRS, err := deploymentutil.GetNewReplicaSet(deployment, h.c)
|
|
||||||
if err != nil {
|
|
||||||
return historyInfo, fmt.Errorf("failed to retrieve new replica set from deployment %s: %v", name, err)
|
|
||||||
}
|
}
|
||||||
allRSs := allOldRSs
|
allRSs := allOldRSs
|
||||||
if newRS != nil {
|
if newRS != nil {
|
||||||
|
@ -47,23 +47,39 @@ const (
|
|||||||
RollbackDone = "DeploymentRollback"
|
RollbackDone = "DeploymentRollback"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GetAllReplicaSets returns the old and new replica sets targeted by the given Deployment. It gets PodList and ReplicaSetList from client interface.
|
||||||
|
// Note that the first set of old replica sets doesn't include the ones with no pods, and the second set of old replica sets include all old replica sets.
|
||||||
|
// The third returned value is the new replica set, and it may be nil if it doesn't exist yet.
|
||||||
|
func GetAllReplicaSets(deployment *extensions.Deployment, c clientset.Interface) ([]*extensions.ReplicaSet, []*extensions.ReplicaSet, *extensions.ReplicaSet, error) {
|
||||||
|
rsList, err := listReplicaSets(deployment, c)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, nil, err
|
||||||
|
}
|
||||||
|
podList, err := listPods(deployment, c)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, nil, err
|
||||||
|
}
|
||||||
|
oldRSes, allOldRSes, err := FindOldReplicaSets(deployment, rsList, podList)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, nil, err
|
||||||
|
}
|
||||||
|
newRS, err := FindNewReplicaSet(deployment, rsList)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, nil, err
|
||||||
|
}
|
||||||
|
return oldRSes, allOldRSes, newRS, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetOldReplicaSets returns the old replica sets targeted by the given Deployment; get PodList and ReplicaSetList from client interface.
|
// GetOldReplicaSets returns the old replica sets targeted by the given Deployment; get PodList and ReplicaSetList from client interface.
|
||||||
// Note that the first set of old replica sets doesn't include the ones with no pods, and the second set of old replica sets include all old replica sets.
|
// Note that the first set of old replica sets doesn't include the ones with no pods, and the second set of old replica sets include all old replica sets.
|
||||||
func GetOldReplicaSets(deployment *extensions.Deployment, c clientset.Interface) ([]*extensions.ReplicaSet, []*extensions.ReplicaSet, error) {
|
func GetOldReplicaSets(deployment *extensions.Deployment, c clientset.Interface) ([]*extensions.ReplicaSet, []*extensions.ReplicaSet, error) {
|
||||||
rsList, err := ListReplicaSets(deployment,
|
rsList, err := listReplicaSets(deployment, c)
|
||||||
func(namespace string, options api.ListOptions) ([]extensions.ReplicaSet, error) {
|
|
||||||
rsList, err := c.Extensions().ReplicaSets(namespace).List(options)
|
|
||||||
return rsList.Items, err
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("error listing ReplicaSets: %v", err)
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
podList, err := ListPods(deployment,
|
podList, err := listPods(deployment, c)
|
||||||
func(namespace string, options api.ListOptions) (*api.PodList, error) {
|
|
||||||
return c.Core().Pods(namespace).List(options)
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("error listing Pods: %v", err)
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
return FindOldReplicaSets(deployment, rsList, podList)
|
return FindOldReplicaSets(deployment, rsList, podList)
|
||||||
}
|
}
|
||||||
@ -71,15 +87,28 @@ func GetOldReplicaSets(deployment *extensions.Deployment, c clientset.Interface)
|
|||||||
// GetNewReplicaSet returns a replica set that matches the intent of the given deployment; get ReplicaSetList from client interface.
|
// GetNewReplicaSet returns a replica set that matches the intent of the given deployment; get ReplicaSetList from client interface.
|
||||||
// Returns nil if the new replica set doesn't exist yet.
|
// Returns nil if the new replica set doesn't exist yet.
|
||||||
func GetNewReplicaSet(deployment *extensions.Deployment, c clientset.Interface) (*extensions.ReplicaSet, error) {
|
func GetNewReplicaSet(deployment *extensions.Deployment, c clientset.Interface) (*extensions.ReplicaSet, error) {
|
||||||
rsList, err := ListReplicaSets(deployment,
|
rsList, err := listReplicaSets(deployment, c)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return FindNewReplicaSet(deployment, rsList)
|
||||||
|
}
|
||||||
|
|
||||||
|
// listReplicaSets lists all RSes the given deployment targets with the given client interface.
|
||||||
|
func listReplicaSets(deployment *extensions.Deployment, c clientset.Interface) ([]extensions.ReplicaSet, error) {
|
||||||
|
return ListReplicaSets(deployment,
|
||||||
func(namespace string, options api.ListOptions) ([]extensions.ReplicaSet, error) {
|
func(namespace string, options api.ListOptions) ([]extensions.ReplicaSet, error) {
|
||||||
rsList, err := c.Extensions().ReplicaSets(namespace).List(options)
|
rsList, err := c.Extensions().ReplicaSets(namespace).List(options)
|
||||||
return rsList.Items, err
|
return rsList.Items, err
|
||||||
})
|
})
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error listing ReplicaSets: %v", err)
|
|
||||||
}
|
}
|
||||||
return FindNewReplicaSet(deployment, rsList)
|
|
||||||
|
// listReplicaSets lists all Pods the given deployment targets with the given client interface.
|
||||||
|
func listPods(deployment *extensions.Deployment, c clientset.Interface) (*api.PodList, error) {
|
||||||
|
return ListPods(deployment,
|
||||||
|
func(namespace string, options api.ListOptions) (*api.PodList, error) {
|
||||||
|
return c.Core().Pods(namespace).List(options)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: switch this to full namespacers
|
// TODO: switch this to full namespacers
|
||||||
|
@ -927,13 +927,11 @@ func testDeploymentLabelAdopted(f *framework.Framework) {
|
|||||||
// There should be no old RSs (overlapping RS)
|
// There should be no old RSs (overlapping RS)
|
||||||
deployment, err := c.Extensions().Deployments(ns).Get(deploymentName)
|
deployment, err := c.Extensions().Deployments(ns).Get(deploymentName)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
oldRSs, allOldRSs, err := deploymentutil.GetOldReplicaSets(deployment, c)
|
oldRSs, allOldRSs, newRS, err := deploymentutil.GetAllReplicaSets(deployment, c)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
Expect(len(oldRSs)).Should(Equal(0))
|
Expect(len(oldRSs)).Should(Equal(0))
|
||||||
Expect(len(allOldRSs)).Should(Equal(0))
|
Expect(len(allOldRSs)).Should(Equal(0))
|
||||||
// New RS should contain pod-template-hash in its selector, label, and template label
|
// New RS should contain pod-template-hash in its selector, label, and template label
|
||||||
newRS, err := deploymentutil.GetNewReplicaSet(deployment, c)
|
|
||||||
Expect(err).NotTo(HaveOccurred())
|
|
||||||
err = framework.CheckRSHashLabel(newRS)
|
err = framework.CheckRSHashLabel(newRS)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
// All pods targeted by the deployment should contain pod-template-hash in their labels, and there should be only 3 pods
|
// All pods targeted by the deployment should contain pod-template-hash in their labels, and there should be only 3 pods
|
||||||
|
@ -2863,11 +2863,7 @@ func WaitForDeploymentStatus(c clientset.Interface, ns, deploymentName string, d
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
oldRSs, allOldRSs, err = deploymentutil.GetOldReplicaSets(deployment, c)
|
oldRSs, allOldRSs, newRS, err = deploymentutil.GetAllReplicaSets(deployment, c)
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
newRS, err = deploymentutil.GetNewReplicaSet(deployment, c)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user