2018-12-03 13:23:12 -07:00
|
|
|
package test
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/rook/rook/pkg/clusterd"
|
2020-07-10 16:40:16 -06:00
|
|
|
"github.com/rook/rook/pkg/daemon/ceph/client"
|
2019-02-04 19:35:45 +00:00
|
|
|
apps "k8s.io/api/apps/v1"
|
2018-12-03 13:23:12 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// UpdateDeploymentAndWaitStub returns a stub replacement for the UpdateDeploymentAndWait function
|
|
|
|
|
// for unit tests which always returns success (nil). The generated simple clientset doesn't seem to
|
|
|
|
|
// handle the Deployment.Update method as expected. The deployment is instead zero-ed out when the
|
|
|
|
|
// deployment is updated with an unchanged version, which breaks unit tests.
|
|
|
|
|
// In order to still test the UpdateDeploymentAndWait function, the stub function returned will
|
|
|
|
|
// append a copy of the deployment used as input to the list of deployments updated. The function
|
|
|
|
|
// returns a pointer to this slice which the calling func may use to verify the expected contents of
|
|
|
|
|
// deploymentsUpdated based on expected behavior.
|
|
|
|
|
func UpdateDeploymentAndWaitStub() (
|
2020-07-10 16:40:16 -06:00
|
|
|
stubFunc func(context *clusterd.Context, clusterInfo *client.ClusterInfo, deployment *apps.Deployment, daemonType, daemonName string, skipUpgradeChecks, continueUpgradeAfterChecksEvenIfNotHealthy bool) error,
|
2019-02-04 19:35:45 +00:00
|
|
|
deploymentsUpdated *[]*apps.Deployment,
|
2018-12-03 13:23:12 -07:00
|
|
|
) {
|
2019-02-04 19:35:45 +00:00
|
|
|
deploymentsUpdated = &[]*apps.Deployment{}
|
2020-07-10 16:40:16 -06:00
|
|
|
stubFunc = func(context *clusterd.Context, clusterInfo *client.ClusterInfo, deployment *apps.Deployment, daemonType, daemonName string, skipUpgradeChecks, continueUpgradeAfterChecksEvenIfNotHealthy bool) error {
|
2018-12-03 13:23:12 -07:00
|
|
|
*deploymentsUpdated = append(*deploymentsUpdated, deployment)
|
2019-03-27 12:34:57 +01:00
|
|
|
return nil
|
2018-12-03 13:23:12 -07:00
|
|
|
}
|
|
|
|
|
return stubFunc, deploymentsUpdated
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DeploymentNamesUpdated converts a deploymentsUpdated slice into a string slice of deployment names
|
2019-02-04 19:35:45 +00:00
|
|
|
func DeploymentNamesUpdated(deploymentsUpdated *[]*apps.Deployment) []string {
|
2018-12-03 13:23:12 -07:00
|
|
|
ns := []string{}
|
|
|
|
|
for _, d := range *deploymentsUpdated {
|
|
|
|
|
ns = append(ns, d.GetName())
|
|
|
|
|
}
|
|
|
|
|
return ns
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ClearDeploymentsUpdated clears the deploymentsUpdated list
|
2019-02-04 19:35:45 +00:00
|
|
|
func ClearDeploymentsUpdated(deploymentsUpdated *[]*apps.Deployment) {
|
|
|
|
|
*deploymentsUpdated = []*apps.Deployment{}
|
2018-12-03 13:23:12 -07:00
|
|
|
}
|