2016-08-11 02:34:31 +00:00
/ *
Copyright 2016 The Kubernetes Authors .
Licensed under the Apache License , Version 2.0 ( the "License" ) ;
you may not use this file except in compliance with the License .
You may obtain a copy of the License at
http : //www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing , software
distributed under the License is distributed on an "AS IS" BASIS ,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND , either express or implied .
See the License for the specific language governing permissions and
limitations under the License .
* /
2017-01-11 13:23:31 +00:00
package e2e_federation
2016-08-11 02:34:31 +00:00
import (
2017-02-08 22:03:19 +00:00
"encoding/json"
2016-08-11 02:34:31 +00:00
"fmt"
2017-02-08 22:03:19 +00:00
"reflect"
2016-09-01 19:36:54 +00:00
"time"
2016-08-11 02:34:31 +00:00
2017-06-22 18:24:23 +00:00
"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
2017-01-11 14:09:48 +00:00
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
2016-12-14 17:57:24 +00:00
fedclientset "k8s.io/kubernetes/federation/client/clientset_generated/federation_clientset"
2016-09-01 19:36:54 +00:00
fedutil "k8s.io/kubernetes/federation/pkg/federation-controller/util"
2016-08-11 02:34:31 +00:00
"k8s.io/kubernetes/test/e2e/framework"
2017-01-11 13:23:31 +00:00
fedframework "k8s.io/kubernetes/test/e2e_federation/framework"
2016-08-11 02:34:31 +00:00
2016-09-01 19:36:54 +00:00
. "github.com/onsi/ginkgo"
2016-08-11 02:34:31 +00:00
. "github.com/onsi/gomega"
2017-01-13 17:48:50 +00:00
"k8s.io/apimachinery/pkg/api/errors"
2017-03-25 00:29:12 +00:00
"k8s.io/apimachinery/pkg/util/uuid"
2017-02-08 22:03:19 +00:00
"k8s.io/kubernetes/federation/apis/federation"
2017-05-26 19:23:16 +00:00
federatedtypes "k8s.io/kubernetes/federation/pkg/federatedtypes"
2016-08-11 02:34:31 +00:00
)
const (
2017-02-27 02:37:37 +00:00
FederationReplicaSetPrefix = "federation-replicaset-"
2016-08-11 02:34:31 +00:00
)
// Create/delete replicaset api objects
2017-03-11 03:43:01 +00:00
var _ = framework . KubeDescribe ( "Federated ReplicaSet [Feature:Federation]" , func ( ) {
2017-01-11 13:23:31 +00:00
f := fedframework . NewDefaultFederatedFramework ( "federation-replicaset" )
2016-08-11 02:34:31 +00:00
2017-01-31 23:09:07 +00:00
Describe ( "ReplicaSet objects [NoCluster]" , func ( ) {
2016-08-11 02:34:31 +00:00
AfterEach ( func ( ) {
2017-01-11 13:23:31 +00:00
fedframework . SkipUnlessFederated ( f . ClientSet )
2016-08-11 02:34:31 +00:00
2016-11-10 01:50:25 +00:00
// Delete all replicasets.
2016-08-22 17:48:43 +00:00
nsName := f . FederationNamespace . Name
2017-01-11 13:23:31 +00:00
deleteAllReplicaSetsOrFail ( f . FederationClientset , nsName )
2016-08-11 02:34:31 +00:00
} )
It ( "should be created and deleted successfully" , func ( ) {
2017-01-11 13:23:31 +00:00
fedframework . SkipUnlessFederated ( f . ClientSet )
2016-08-22 17:48:43 +00:00
nsName := f . FederationNamespace . Name
2017-02-27 02:37:37 +00:00
rs := createReplicaSetOrFail ( f . FederationClientset , newReplicaSet ( nsName , FederationReplicaSetPrefix , 5 , nil ) )
2017-02-08 22:03:19 +00:00
By ( fmt . Sprintf ( "Creation of replicaset %q in namespace %q succeeded. Deleting replicaset." , rs . Name , nsName ) )
2016-08-11 02:34:31 +00:00
// Cleanup
2017-02-08 22:03:19 +00:00
err := f . FederationClientset . Extensions ( ) . ReplicaSets ( nsName ) . Delete ( rs . Name , & metav1 . DeleteOptions { } )
framework . ExpectNoError ( err , "Error deleting replicaset %q in namespace %q" , rs . Name , rs . Namespace )
By ( fmt . Sprintf ( "Deletion of replicaset %q in namespace %q succeeded." , rs . Name , nsName ) )
2016-08-11 02:34:31 +00:00
} )
} )
2016-09-01 19:36:54 +00:00
// e2e cases for federated replicaset controller
2017-03-11 03:43:01 +00:00
Describe ( "Features" , func ( ) {
2016-09-01 19:36:54 +00:00
var (
2017-04-04 16:21:38 +00:00
clusters fedframework . ClusterSlice
2016-09-01 19:36:54 +00:00
)
2017-03-11 03:43:01 +00:00
2016-09-01 19:36:54 +00:00
BeforeEach ( func ( ) {
2017-01-11 13:23:31 +00:00
fedframework . SkipUnlessFederated ( f . ClientSet )
2017-04-04 16:21:38 +00:00
clusters = f . GetRegisteredClusters ( )
2016-09-01 19:36:54 +00:00
} )
2017-03-11 03:43:01 +00:00
// e2e cases for federated replicaset controller
Describe ( "Preferences" , func ( ) {
var (
rs * v1beta1 . ReplicaSet
)
AfterEach ( func ( ) {
// Delete all replicasets.
nsName := f . FederationNamespace . Name
if rs != nil {
orphanDependents := false
By ( fmt . Sprintf ( "Deleting replicaset \"%s/%s\"" , nsName , rs . Name ) )
deleteReplicaSetOrFail ( f . FederationClientset , nsName , rs . Name , & orphanDependents )
rs = nil
}
} )
2017-02-08 22:03:19 +00:00
2017-03-11 03:43:01 +00:00
It ( "should create replicasets with weight preference" , func ( ) {
pref , replicas , expect := generateFedRSPrefsWithWeight ( clusters )
rs = createAndUpdateFedRSWithPref ( f . FederationClientset , f . FederationNamespace . Name , clusters , pref , replicas , expect )
} )
2017-02-08 22:03:19 +00:00
2017-03-11 03:43:01 +00:00
It ( "should create replicasets with min replicas preference" , func ( ) {
pref , replicas , expect := generateFedRSPrefsWithMin ( clusters )
rs = createAndUpdateFedRSWithPref ( f . FederationClientset , f . FederationNamespace . Name , clusters , pref , replicas , expect )
} )
2017-02-08 22:03:19 +00:00
2017-03-11 03:43:01 +00:00
It ( "should create replicasets with max replicas preference" , func ( ) {
pref , replicas , expect := generateFedRSPrefsWithMax ( clusters )
rs = createAndUpdateFedRSWithPref ( f . FederationClientset , f . FederationNamespace . Name , clusters , pref , replicas , expect )
} )
2017-02-08 22:03:19 +00:00
// test for rebalancing
2017-03-25 00:34:10 +00:00
PIt ( "should create replicasets and rebalance them" , func ( ) {
2017-03-11 03:43:01 +00:00
nsName := f . FederationNamespace . Name
pref1 , pref2 , replicas , expect1 , expect2 := generateFedRSPrefsForRebalancing ( clusters )
By ( "Testing replicaset rebalancing" )
framework . Logf ( "Replicas: %d" , replicas )
framework . Logf ( "Preference 1: %#v" , pref1 )
framework . Logf ( "Preference 2: %#v" , pref2 )
rs = newReplicaSet ( nsName , FederationReplicaSetPrefix , replicas , pref1 )
2017-02-08 22:03:19 +00:00
rs = createReplicaSetOrFail ( f . FederationClientset , rs )
waitForReplicaSetOrFail ( f . FederationClientset , nsName , rs . Name , clusters , expect1 )
2017-03-11 03:43:01 +00:00
By ( fmt . Sprintf ( "Successfully created and synced replicaset \"%s/%s\" (%v/%v) to clusters" , nsName , rs . Name , rs . Status . Replicas , * rs . Spec . Replicas ) )
2017-02-08 22:03:19 +00:00
2017-03-09 19:16:42 +00:00
rs = newReplicaSetWithName ( nsName , rs . Name , replicas , pref2 )
2017-02-08 22:03:19 +00:00
updateReplicaSetOrFail ( f . FederationClientset , rs )
waitForReplicaSetOrFail ( f . FederationClientset , nsName , rs . Name , clusters , expect1 )
2017-03-11 03:43:01 +00:00
By ( fmt . Sprintf ( "Successfully updated and synced replicaset \"%s/%s\" (%v/%v) to clusters" , nsName , rs . Name , rs . Status . Replicas , * rs . Spec . Replicas ) )
2017-02-08 22:03:19 +00:00
2017-03-11 03:43:01 +00:00
pref2 = updateFedRSPrefsRebalance ( pref2 , true )
2017-03-09 19:16:42 +00:00
rs = newReplicaSetWithName ( nsName , rs . Name , replicas , pref2 )
2017-02-08 22:03:19 +00:00
updateReplicaSetOrFail ( f . FederationClientset , rs )
waitForReplicaSetOrFail ( f . FederationClientset , nsName , rs . Name , clusters , expect2 )
2017-03-11 03:43:01 +00:00
By ( fmt . Sprintf ( "Successfully updated and synced replicaset \"%s/%s\" (%v/%v) to clusters" , nsName , rs . Name , rs . Status . Replicas , * rs . Spec . Replicas ) )
} )
2016-11-10 01:50:25 +00:00
} )
2016-09-01 19:36:54 +00:00
} )
2016-08-11 02:34:31 +00:00
} )
2017-04-04 16:21:38 +00:00
func createAndWaitForReplicasetOrFail ( clientset * fedclientset . Clientset , nsName string , clusters fedframework . ClusterSlice ) * v1beta1 . ReplicaSet {
2017-03-11 03:43:01 +00:00
rs := createReplicaSetOrFail ( clientset , newReplicaSet ( nsName , FederationReplicaSetPrefix , 5 , nil ) )
2016-11-10 01:50:25 +00:00
// Check subclusters if the replicaSet was created there.
2017-03-11 03:43:01 +00:00
By ( fmt . Sprintf ( "Waiting for replica sets %s to be created in all underlying clusters" , rs . Name ) )
2016-11-10 01:50:25 +00:00
err := wait . Poll ( 5 * time . Second , 2 * time . Minute , func ( ) ( bool , error ) {
for _ , cluster := range clusters {
2017-03-11 03:43:01 +00:00
_ , err := cluster . Extensions ( ) . ReplicaSets ( nsName ) . Get ( rs . Name , metav1 . GetOptions { } )
2016-11-10 01:50:25 +00:00
if err != nil && errors . IsNotFound ( err ) {
return false , nil
}
if err != nil {
return false , err
}
}
return true , nil
} )
framework . ExpectNoError ( err , "Not all replica sets created" )
2017-03-11 03:43:01 +00:00
return rs
}
2016-11-10 01:50:25 +00:00
2017-04-15 09:13:20 +00:00
func createAndUpdateFedRSWithPref ( clientset * fedclientset . Clientset , nsName string , clusters fedframework . ClusterSlice , pref * federation . ReplicaAllocationPreferences , replicas int32 , expect map [ string ] int32 ) * v1beta1 . ReplicaSet {
2017-03-11 03:43:01 +00:00
framework . Logf ( "Replicas: %d, Preference: %#v" , replicas , pref )
rs := newReplicaSet ( nsName , FederationReplicaSetPrefix , replicas , pref )
rs = createReplicaSetOrFail ( clientset , rs )
2016-11-10 01:50:25 +00:00
2017-03-11 03:43:01 +00:00
waitForReplicaSetOrFail ( clientset , nsName , rs . Name , clusters , expect )
By ( fmt . Sprintf ( "Successfully created and synced replicaset \"%s/%s\" (%v/%v) to clusters" , nsName , rs . Name , rs . Status . Replicas , * rs . Spec . Replicas ) )
rs = newReplicaSetWithName ( nsName , rs . Name , 0 , pref )
updateReplicaSetOrFail ( clientset , rs )
waitForReplicaSetOrFail ( clientset , nsName , rs . Name , clusters , nil )
By ( fmt . Sprintf ( "Successfully updated and synced replicaset \"%s/%s\" (%v/%v) to clusters" , nsName , rs . Name , rs . Status . Replicas , * rs . Spec . Replicas ) )
rs = newReplicaSetWithName ( nsName , rs . Name , replicas , pref )
updateReplicaSetOrFail ( clientset , rs )
waitForReplicaSetOrFail ( clientset , nsName , rs . Name , clusters , expect )
By ( fmt . Sprintf ( "Successfully updated and synced replicaset \"%s/%s\" (%v/%v) to clusters" , nsName , rs . Name , rs . Status . Replicas , * rs . Spec . Replicas ) )
return rs
}
// deleteAllReplicaSetsOrFail deletes all replicasets in the given namespace name.
func deleteAllReplicaSetsOrFail ( clientset * fedclientset . Clientset , nsName string ) {
replicasetList , err := clientset . Extensions ( ) . ReplicaSets ( nsName ) . List ( metav1 . ListOptions { } )
Expect ( err ) . NotTo ( HaveOccurred ( ) )
orphanDependents := false
for _ , replicaset := range replicasetList . Items {
deleteReplicaSetOrFail ( clientset , nsName , replicaset . Name , & orphanDependents )
}
}
2017-04-15 09:13:20 +00:00
func generateFedRSPrefsWithWeight ( clusters fedframework . ClusterSlice ) ( pref * federation . ReplicaAllocationPreferences , replicas int32 , expect map [ string ] int32 ) {
2017-03-11 03:43:01 +00:00
By ( "Generating replicaset preferences with weights" )
2017-03-13 23:36:08 +00:00
clusterNames := extractClusterNames ( clusters )
2017-04-15 09:13:20 +00:00
pref = & federation . ReplicaAllocationPreferences {
Clusters : map [ string ] federation . ClusterPreferences { } ,
2017-02-08 22:03:19 +00:00
}
replicas = 0
expect = map [ string ] int32 { }
for i , clusterName := range clusterNames {
if i != 0 { // do not set weight for cluster[0] thus it should have no replicas scheduled
2017-04-15 09:13:20 +00:00
pref . Clusters [ clusterName ] = federation . ClusterPreferences {
2017-03-11 03:43:01 +00:00
Weight : int64 ( i ) ,
}
2017-02-08 22:03:19 +00:00
replicas += int32 ( i )
expect [ clusterName ] = int32 ( i )
}
}
return
}
2017-04-15 09:13:20 +00:00
func generateFedRSPrefsWithMin ( clusters fedframework . ClusterSlice ) ( pref * federation . ReplicaAllocationPreferences , replicas int32 , expect map [ string ] int32 ) {
2017-03-11 03:43:01 +00:00
By ( "Generating replicaset preferences with min replicas" )
2017-03-13 23:36:08 +00:00
clusterNames := extractClusterNames ( clusters )
2017-04-15 09:13:20 +00:00
pref = & federation . ReplicaAllocationPreferences {
Clusters : map [ string ] federation . ClusterPreferences {
2017-02-08 22:03:19 +00:00
clusterNames [ 0 ] : { Weight : 100 } ,
} ,
}
replicas = 0
expect = map [ string ] int32 { }
for i , clusterName := range clusterNames {
if i != 0 { // do not set weight and minReplicas for cluster[0] thus it should have no replicas scheduled
2017-04-15 09:13:20 +00:00
pref . Clusters [ clusterName ] = federation . ClusterPreferences {
2017-03-11 03:43:01 +00:00
Weight : int64 ( 1 ) ,
MinReplicas : int64 ( i + 2 ) ,
}
2017-02-08 22:03:19 +00:00
replicas += int32 ( i + 2 )
expect [ clusterName ] = int32 ( i + 2 )
}
}
// the extra replica goes to cluster[0] which has the highest weight
replicas += 1
expect [ clusterNames [ 0 ] ] = 1
return
}
2017-04-15 09:13:20 +00:00
func generateFedRSPrefsWithMax ( clusters fedframework . ClusterSlice ) ( pref * federation . ReplicaAllocationPreferences , replicas int32 , expect map [ string ] int32 ) {
2017-03-11 03:43:01 +00:00
By ( "Generating replicaset preferences with max replicas" )
2017-03-13 23:36:08 +00:00
clusterNames := extractClusterNames ( clusters )
2017-04-15 09:13:20 +00:00
pref = & federation . ReplicaAllocationPreferences {
Clusters : map [ string ] federation . ClusterPreferences {
2017-02-08 22:03:19 +00:00
clusterNames [ 0 ] : { Weight : 1 } ,
} ,
}
replicas = 0
expect = map [ string ] int32 { }
for i , clusterName := range clusterNames {
if i != 0 { // do not set maxReplicas for cluster[0] thus replicas exceeds the total maxReplicas turned to cluster[0]
maxReplicas := int64 ( i )
2017-04-15 09:13:20 +00:00
pref . Clusters [ clusterName ] = federation . ClusterPreferences {
2017-03-11 03:43:01 +00:00
Weight : int64 ( 100 ) ,
MaxReplicas : & maxReplicas ,
}
2017-02-08 22:03:19 +00:00
replicas += int32 ( i )
expect [ clusterName ] = int32 ( i )
}
}
// extra replicas go to cluster[0] although it has the lowest weight as others hit the MaxReplicas
replicas += 5
expect [ clusterNames [ 0 ] ] = 5
return
}
2017-04-15 09:13:20 +00:00
func updateFedRSPrefsRebalance ( pref * federation . ReplicaAllocationPreferences , rebalance bool ) * federation . ReplicaAllocationPreferences {
2017-02-08 22:03:19 +00:00
pref . Rebalance = rebalance
return pref
}
2017-04-15 09:13:20 +00:00
func generateFedRSPrefsForRebalancing ( clusters fedframework . ClusterSlice ) ( pref1 , pref2 * federation . ReplicaAllocationPreferences , replicas int32 , expect1 , expect2 map [ string ] int32 ) {
2017-03-11 03:43:01 +00:00
By ( "Generating replicaset for rebalancing" )
2017-03-13 23:36:08 +00:00
clusterNames := extractClusterNames ( clusters )
2017-02-08 22:03:19 +00:00
replicas = 3
2017-04-15 09:13:20 +00:00
pref1 = & federation . ReplicaAllocationPreferences {
Clusters : map [ string ] federation . ClusterPreferences {
2017-02-08 22:03:19 +00:00
clusterNames [ 0 ] : { Weight : 1 } ,
clusterNames [ 1 ] : { Weight : 2 } ,
} ,
}
expect1 = map [ string ] int32 {
clusterNames [ 0 ] : 1 ,
clusterNames [ 1 ] : 2 ,
}
2017-04-15 09:13:20 +00:00
pref2 = & federation . ReplicaAllocationPreferences {
Clusters : map [ string ] federation . ClusterPreferences {
2017-02-08 22:03:19 +00:00
clusterNames [ 0 ] : { Weight : 2 } ,
clusterNames [ 1 ] : { Weight : 1 } ,
} ,
}
expect2 = map [ string ] int32 {
clusterNames [ 0 ] : 2 ,
clusterNames [ 1 ] : 1 ,
}
return
}
2017-04-04 16:21:38 +00:00
func waitForReplicaSetOrFail ( c * fedclientset . Clientset , namespace string , replicaSetName string , clusters fedframework . ClusterSlice , expect map [ string ] int32 ) {
2017-02-08 22:03:19 +00:00
err := waitForReplicaSet ( c , namespace , replicaSetName , clusters , expect )
2017-03-11 03:43:01 +00:00
framework . ExpectNoError ( err , "Failed to verify replica set \"%s/%s\", err: %v" , namespace , replicaSetName , err )
2016-09-01 19:36:54 +00:00
}
2017-04-04 16:21:38 +00:00
func waitForReplicaSet ( c * fedclientset . Clientset , namespace string , replicaSetName string , clusters fedframework . ClusterSlice , expect map [ string ] int32 ) error {
2017-03-11 03:43:01 +00:00
framework . Logf ( "waitForReplicaSet: %s/%s; clusters: %v; expect: %v" , namespace , replicaSetName , clusters , expect )
2017-03-22 05:28:59 +00:00
err := wait . Poll ( 10 * time . Second , fedframework . FederatedDefaultTestTimeout , func ( ) ( bool , error ) {
2017-07-21 10:46:24 +00:00
frs , err := c . ExtensionsV1beta1 ( ) . ReplicaSets ( namespace ) . Get ( replicaSetName , metav1 . GetOptions { } )
2016-09-01 19:36:54 +00:00
if err != nil {
return false , err
}
specReplicas , statusReplicas := int32 ( 0 ) , int32 ( 0 )
for _ , cluster := range clusters {
2017-07-20 18:04:11 +00:00
// TODO: switch to use AppsV1beta2 ReplicaSet when apps/v1beta2 is enabled by default
rs , err := cluster . ExtensionsV1beta1 ( ) . ReplicaSets ( namespace ) . Get ( replicaSetName , metav1 . GetOptions { } )
2016-09-01 19:36:54 +00:00
if err != nil && ! errors . IsNotFound ( err ) {
2017-03-22 05:28:59 +00:00
framework . Logf ( "Failed getting replicaset: \"%s/%s/%s\", err: %v" , cluster . Name , namespace , replicaSetName , err )
2016-09-01 19:36:54 +00:00
return false , err
}
2017-02-08 22:03:19 +00:00
if errors . IsNotFound ( err ) {
2017-03-22 05:28:59 +00:00
if expect != nil && expect [ cluster . Name ] > 0 {
framework . Logf ( "Replicaset \"%s/%s/%s\" with replica count %d does not exist" , cluster . Name , namespace , replicaSetName , expect [ cluster . Name ] )
2017-02-08 22:03:19 +00:00
return false , nil
}
} else {
2016-09-01 19:36:54 +00:00
if ! equivalentReplicaSet ( frs , rs ) {
2017-03-22 05:28:59 +00:00
framework . Logf ( "Replicaset meta or spec does not match for cluster %q:\n federation: %v\n cluster: %v" , cluster . Name , frs , rs )
2016-09-01 19:36:54 +00:00
return false , nil
}
2017-03-22 05:28:59 +00:00
if expect != nil && * rs . Spec . Replicas < expect [ cluster . Name ] {
framework . Logf ( "Replicas do not match for \"%s/%s/%s\": expected: >= %v, actual: %v" , cluster . Name , namespace , replicaSetName , expect [ cluster . Name ] , * rs . Spec . Replicas )
2017-02-08 22:03:19 +00:00
return false , nil
}
2016-09-01 19:36:54 +00:00
specReplicas += * rs . Spec . Replicas
statusReplicas += rs . Status . Replicas
}
}
2017-02-08 22:03:19 +00:00
if * frs . Spec . Replicas == 0 && frs . Status . Replicas != 0 {
2017-03-11 03:43:01 +00:00
framework . Logf ( "ReplicaSet \"%s/%s\" with zero replicas should match the status as no overflow happens: expected: 0, actual: %v" , namespace , replicaSetName , frs . Status . Replicas )
2017-02-08 22:03:19 +00:00
return false , nil
}
2016-09-01 19:36:54 +00:00
if statusReplicas == frs . Status . Replicas && specReplicas >= * frs . Spec . Replicas {
return true , nil
}
2017-03-11 03:43:01 +00:00
framework . Logf ( "Replicas do not match, federation replicas: %v/%v, cluster replicas: %v/%v" , frs . Status . Replicas , * frs . Spec . Replicas , statusReplicas , specReplicas )
2016-09-01 19:36:54 +00:00
return false , nil
} )
return err
}
func equivalentReplicaSet ( fedReplicaSet , localReplicaSet * v1beta1 . ReplicaSet ) bool {
localReplicaSetSpec := localReplicaSet . Spec
localReplicaSetSpec . Replicas = fedReplicaSet . Spec . Replicas
return fedutil . ObjectMetaEquivalent ( fedReplicaSet . ObjectMeta , localReplicaSet . ObjectMeta ) &&
reflect . DeepEqual ( fedReplicaSet . Spec , localReplicaSetSpec )
}
2017-02-08 22:03:19 +00:00
func createReplicaSetOrFail ( clientset * fedclientset . Clientset , replicaset * v1beta1 . ReplicaSet ) * v1beta1 . ReplicaSet {
namespace := replicaset . Namespace
2016-08-11 02:34:31 +00:00
if clientset == nil || len ( namespace ) == 0 {
Fail ( fmt . Sprintf ( "Internal error: invalid parameters passed to createReplicaSetOrFail: clientset: %v, namespace: %v" , clientset , namespace ) )
}
2017-02-27 02:37:37 +00:00
By ( fmt . Sprintf ( "Creating federation replicaset %q in namespace %q" , replicaset . Name , namespace ) )
2016-08-11 02:34:31 +00:00
2017-03-08 04:50:08 +00:00
newRS , err := clientset . Extensions ( ) . ReplicaSets ( namespace ) . Create ( replicaset )
2016-09-01 19:36:54 +00:00
framework . ExpectNoError ( err , "Creating replicaset %q in namespace %q" , replicaset . Name , namespace )
2017-03-08 04:50:08 +00:00
By ( fmt . Sprintf ( "Successfully created federation replicaset %q in namespace %q" , newRS . Name , namespace ) )
return newRS
2016-09-01 19:36:54 +00:00
}
2016-11-10 01:50:25 +00:00
func deleteReplicaSetOrFail ( clientset * fedclientset . Clientset , nsName string , replicaSetName string , orphanDependents * bool ) {
By ( fmt . Sprintf ( "Deleting replica set %q in namespace %q" , replicaSetName , nsName ) )
2017-01-24 15:38:21 +00:00
err := clientset . Extensions ( ) . ReplicaSets ( nsName ) . Delete ( replicaSetName , & metav1 . DeleteOptions { OrphanDependents : orphanDependents } )
2017-02-03 15:48:34 +00:00
if err != nil && ! errors . IsNotFound ( err ) {
framework . ExpectNoError ( err , "Error deleting replica set %q in namespace %q" , replicaSetName , nsName )
}
2016-11-10 01:50:25 +00:00
2017-02-11 01:12:07 +00:00
waitForReplicaSetToBeDeletedOrFail ( clientset , nsName , replicaSetName )
2016-11-10 01:50:25 +00:00
}
2017-02-08 22:03:19 +00:00
func updateReplicaSetOrFail ( clientset * fedclientset . Clientset , replicaset * v1beta1 . ReplicaSet ) * v1beta1 . ReplicaSet {
namespace := replicaset . Namespace
2016-09-01 19:36:54 +00:00
if clientset == nil || len ( namespace ) == 0 {
Fail ( fmt . Sprintf ( "Internal error: invalid parameters passed to updateReplicaSetOrFail: clientset: %v, namespace: %v" , clientset , namespace ) )
}
2017-02-27 02:37:37 +00:00
By ( fmt . Sprintf ( "Updating federation replicaset %q in namespace %q" , replicaset . Name , namespace ) )
2016-09-01 19:36:54 +00:00
2017-07-21 10:46:24 +00:00
newRS , err := clientset . ExtensionsV1beta1 ( ) . ReplicaSets ( namespace ) . Update ( replicaset )
2016-09-01 19:36:54 +00:00
framework . ExpectNoError ( err , "Updating replicaset %q in namespace %q" , replicaset . Name , namespace )
2017-02-27 02:37:37 +00:00
By ( fmt . Sprintf ( "Successfully updated federation replicaset %q in namespace %q" , replicaset . Name , namespace ) )
2016-09-01 19:36:54 +00:00
2017-03-09 19:16:42 +00:00
return newRS
2016-09-01 19:36:54 +00:00
}
2017-04-15 09:13:20 +00:00
func newReplicaSetObj ( namespace string , replicas int32 , pref * federation . ReplicaAllocationPreferences ) * v1beta1 . ReplicaSet {
2017-03-25 00:29:12 +00:00
// When the tests are run in parallel, replicasets from different tests can
// collide with each other. Prevent that by creating a unique label and
// label selector for each created replica set.
uuidString := string ( uuid . NewUUID ( ) )
rsLabel := fmt . Sprintf ( "myrs-%s" , uuidString )
2017-03-09 19:16:42 +00:00
rs := & v1beta1 . ReplicaSet {
2017-01-17 03:38:19 +00:00
ObjectMeta : metav1 . ObjectMeta {
2017-03-09 19:16:42 +00:00
Namespace : namespace ,
Annotations : map [ string ] string { } ,
2016-08-11 02:34:31 +00:00
} ,
Spec : v1beta1 . ReplicaSetSpec {
Replicas : & replicas ,
2016-12-03 18:57:26 +00:00
Selector : & metav1 . LabelSelector {
2017-03-25 00:29:12 +00:00
MatchLabels : map [ string ] string { "name" : rsLabel } ,
2016-09-01 19:36:54 +00:00
} ,
2016-08-11 02:34:31 +00:00
Template : v1 . PodTemplateSpec {
2017-01-17 03:38:19 +00:00
ObjectMeta : metav1 . ObjectMeta {
2017-03-25 00:29:12 +00:00
Labels : map [ string ] string { "name" : rsLabel } ,
2016-08-11 02:34:31 +00:00
} ,
Spec : v1 . PodSpec {
Containers : [ ] v1 . Container {
{
Name : "nginx" ,
Image : "nginx" ,
} ,
} ,
} ,
} ,
} ,
}
2017-02-08 22:03:19 +00:00
if pref != nil {
prefBytes , _ := json . Marshal ( pref )
prefString := string ( prefBytes )
2017-05-26 19:23:16 +00:00
rs . Annotations [ federatedtypes . FedReplicaSetPreferencesAnnotation ] = prefString
2017-02-08 22:03:19 +00:00
}
2017-03-09 19:16:42 +00:00
return rs
}
2017-04-15 09:13:20 +00:00
func newReplicaSet ( namespace string , prefix string , replicas int32 , pref * federation . ReplicaAllocationPreferences ) * v1beta1 . ReplicaSet {
2017-03-09 19:16:42 +00:00
rs := newReplicaSetObj ( namespace , replicas , pref )
rs . GenerateName = prefix
return rs
}
2017-04-15 09:13:20 +00:00
func newReplicaSetWithName ( namespace string , name string , replicas int32 , pref * federation . ReplicaAllocationPreferences ) * v1beta1 . ReplicaSet {
2017-03-09 19:16:42 +00:00
rs := newReplicaSetObj ( namespace , replicas , pref )
rs . Name = name
return rs
2017-02-08 22:03:19 +00:00
}
2017-04-04 16:21:38 +00:00
func extractClusterNames ( clusters fedframework . ClusterSlice ) [ ] string {
2017-02-08 22:03:19 +00:00
clusterNames := make ( [ ] string , 0 , len ( clusters ) )
2017-04-04 16:21:38 +00:00
for _ , cluster := range clusters {
clusterNames = append ( clusterNames , cluster . Name )
2017-02-08 22:03:19 +00:00
}
return clusterNames
2016-08-11 02:34:31 +00:00
}