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-11-10 01:50:25 +00:00
"strings"
2016-09-01 19:36:54 +00:00
"time"
2016-08-11 02:34:31 +00:00
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/pkg/api/v1"
"k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
"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-02-08 22:03:19 +00:00
"k8s.io/kubernetes/federation/apis/federation"
fedreplicsetcontroller "k8s.io/kubernetes/federation/pkg/federation-controller/replicaset"
2016-08-11 02:34:31 +00:00
)
const (
2016-09-01 19:36:54 +00:00
FederationReplicaSetName = "federation-replicaset"
FederatedReplicaSetTimeout = 120 * time . Second
2016-08-11 02:34:31 +00:00
)
// Create/delete replicaset api objects
var _ = framework . KubeDescribe ( "Federation replicasets [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-08 22:03:19 +00:00
rs := createReplicaSetOrFail ( f . FederationClientset , newReplicaSet ( nsName , FederationReplicaSetName , 5 , nil ) )
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
Describe ( "Federated ReplicaSet" , func ( ) {
var (
2017-02-03 10:06:28 +00:00
clusters map [ string ] * cluster
2016-09-01 19:36:54 +00:00
)
BeforeEach ( func ( ) {
2017-01-11 13:23:31 +00:00
fedframework . SkipUnlessFederated ( f . ClientSet )
2017-02-03 10:06:28 +00:00
clusters , _ = getRegisteredClusters ( UserAgentName , f )
2016-09-01 19:36:54 +00:00
} )
AfterEach ( func ( ) {
2016-11-10 01:50:25 +00:00
// Delete all replicasets.
nsName := f . FederationNamespace . Name
2017-01-11 13:23:31 +00:00
deleteAllReplicaSetsOrFail ( f . FederationClientset , nsName )
2016-09-01 19:36:54 +00:00
} )
It ( "should create and update matching replicasets in underling clusters" , func ( ) {
2016-09-13 01:46:01 +00:00
nsName := f . FederationNamespace . Name
2017-02-08 22:03:19 +00:00
cleanupFn := func ( rs * v1beta1 . ReplicaSet ) {
// cleanup. deletion of replicasets is not supported for underling clusters
By ( fmt . Sprintf ( "zero replicas then delete replicaset %q/%q" , nsName , rs . Name ) )
zeroReplicas := int32 ( 0 )
rs . Spec . Replicas = & zeroReplicas
updateReplicaSetOrFail ( f . FederationClientset , rs )
waitForReplicaSetOrFail ( f . FederationClientset , nsName , rs . Name , clusters , nil )
2017-01-24 15:38:21 +00:00
f . FederationClientset . ReplicaSets ( nsName ) . Delete ( rs . Name , & metav1 . DeleteOptions { } )
2017-02-08 22:03:19 +00:00
}
// general test with default replicaset pref
func ( ) {
rs := newReplicaSet ( nsName , FederationReplicaSetName , 5 , nil )
rs = createReplicaSetOrFail ( f . FederationClientset , rs )
defer cleanupFn ( rs )
waitForReplicaSetOrFail ( f . FederationClientset , nsName , rs . Name , clusters , nil )
By ( fmt . Sprintf ( "Successfuly created and synced replicaset %q/%q (%v/%v) to clusters" , nsName , rs . Name , * rs . Spec . Replicas , rs . Status . Replicas ) )
rs = newReplicaSet ( nsName , FederationReplicaSetName , 15 , nil )
updateReplicaSetOrFail ( f . FederationClientset , rs )
waitForReplicaSetOrFail ( f . FederationClientset , nsName , rs . Name , clusters , nil )
By ( fmt . Sprintf ( "Successfuly updated and synced replicaset %q/%q (%v/%v) to clusters" , nsName , rs . Name , * rs . Spec . Replicas , rs . Status . Replicas ) )
2016-09-01 19:36:54 +00:00
} ( )
2017-02-08 22:03:19 +00:00
// test for replicaset prefs with weight, min and max replicas
createAndUpdateFn := func ( pref * federation . FederatedReplicaSetPreferences , replicas int32 , expect map [ string ] int32 ) {
rs := newReplicaSet ( nsName , FederationReplicaSetName , replicas , pref )
createReplicaSetOrFail ( f . FederationClientset , rs )
defer cleanupFn ( rs )
waitForReplicaSetOrFail ( f . FederationClientset , nsName , rs . Name , clusters , expect )
By ( fmt . Sprintf ( "Successfuly created and synced replicaset %q/%q (%v/%v) to clusters" , nsName , rs . Name , * rs . Spec . Replicas , rs . Status . Replicas ) )
rs = newReplicaSet ( nsName , FederationReplicaSetName , 0 , pref )
updateReplicaSetOrFail ( f . FederationClientset , rs )
waitForReplicaSetOrFail ( f . FederationClientset , nsName , rs . Name , clusters , nil )
By ( fmt . Sprintf ( "Successfuly updated and synced replicaset %q/%q (%v/%v) to clusters" , nsName , rs . Name , * rs . Spec . Replicas , rs . Status . Replicas ) )
rs = newReplicaSet ( nsName , FederationReplicaSetName , replicas , pref )
updateReplicaSetOrFail ( f . FederationClientset , rs )
waitForReplicaSetOrFail ( f . FederationClientset , nsName , rs . Name , clusters , expect )
By ( fmt . Sprintf ( "Successfuly updated and synced replicaset %q/%q (%v/%v) to clusters" , nsName , rs . Name , * rs . Spec . Replicas , rs . Status . Replicas ) )
}
createAndUpdateFn ( generageFedRsPrefsWithWeight ( clusters ) )
createAndUpdateFn ( generageFedRsPrefsWithMin ( clusters ) )
createAndUpdateFn ( generageFedRsPrefsWithMax ( clusters ) )
// test for rebalancing
func ( ) {
pref1 , pref2 , replicas , expect1 , expect2 := generageFedRsPrefsForRebalancing ( clusters )
rs := newReplicaSet ( nsName , FederationReplicaSetName , replicas , pref1 )
rs = createReplicaSetOrFail ( f . FederationClientset , rs )
defer cleanupFn ( rs )
waitForReplicaSetOrFail ( f . FederationClientset , nsName , rs . Name , clusters , expect1 )
By ( fmt . Sprintf ( "Successfuly created and synced replicaset %q/%q (%v/%v) to clusters" , nsName , rs . Name , * rs . Spec . Replicas , rs . Status . Replicas ) )
rs = newReplicaSet ( nsName , FederationReplicaSetName , replicas , pref2 )
updateReplicaSetOrFail ( f . FederationClientset , rs )
waitForReplicaSetOrFail ( f . FederationClientset , nsName , rs . Name , clusters , expect1 )
By ( fmt . Sprintf ( "Successfuly updated and synced replicaset %q/%q (%v/%v) to clusters" , nsName , rs . Name , * rs . Spec . Replicas , rs . Status . Replicas ) )
pref2 = updateFedRePrefsRebalance ( pref2 , true )
rs = newReplicaSet ( nsName , FederationReplicaSetName , replicas , pref2 )
updateReplicaSetOrFail ( f . FederationClientset , rs )
waitForReplicaSetOrFail ( f . FederationClientset , nsName , rs . Name , clusters , expect2 )
By ( fmt . Sprintf ( "Successfuly updated and synced replicaset %q/%q (%v/%v) to clusters" , nsName , rs . Name , * rs . Spec . Replicas , rs . Status . Replicas ) )
} ( )
2016-09-01 19:36:54 +00:00
} )
2016-11-10 01:50:25 +00:00
It ( "should be deleted from underlying clusters when OrphanDependents is false" , func ( ) {
2017-01-11 13:23:31 +00:00
fedframework . SkipUnlessFederated ( f . ClientSet )
2016-11-10 01:50:25 +00:00
nsName := f . FederationNamespace . Name
orphanDependents := false
2017-01-11 13:23:31 +00:00
verifyCascadingDeletionForReplicaSet ( f . FederationClientset , clusters , & orphanDependents , nsName )
2016-11-10 01:50:25 +00:00
By ( fmt . Sprintf ( "Verified that replica sets were deleted from underlying clusters" ) )
} )
It ( "should not be deleted from underlying clusters when OrphanDependents is true" , func ( ) {
2017-01-11 13:23:31 +00:00
fedframework . SkipUnlessFederated ( f . ClientSet )
2016-11-10 01:50:25 +00:00
nsName := f . FederationNamespace . Name
orphanDependents := true
2017-01-11 13:23:31 +00:00
verifyCascadingDeletionForReplicaSet ( f . FederationClientset , clusters , & orphanDependents , nsName )
2016-11-10 01:50:25 +00:00
By ( fmt . Sprintf ( "Verified that replica sets were not deleted from underlying clusters" ) )
} )
It ( "should not be deleted from underlying clusters when OrphanDependents is nil" , func ( ) {
2017-01-11 13:23:31 +00:00
fedframework . SkipUnlessFederated ( f . ClientSet )
2016-11-10 01:50:25 +00:00
nsName := f . FederationNamespace . Name
2017-01-11 13:23:31 +00:00
verifyCascadingDeletionForReplicaSet ( f . FederationClientset , clusters , nil , nsName )
2016-11-10 01:50:25 +00:00
By ( fmt . Sprintf ( "Verified that replica sets were not deleted from underlying clusters" ) )
} )
2016-09-01 19:36:54 +00:00
} )
2016-08-11 02:34:31 +00:00
} )
2016-11-10 01:50:25 +00:00
// deleteAllReplicaSetsOrFail deletes all replicasets in the given namespace name.
func deleteAllReplicaSetsOrFail ( clientset * fedclientset . Clientset , nsName string ) {
2017-01-22 03:36:02 +00:00
replicasetList , err := clientset . Extensions ( ) . ReplicaSets ( nsName ) . List ( metav1 . ListOptions { } )
2016-11-10 01:50:25 +00:00
Expect ( err ) . NotTo ( HaveOccurred ( ) )
orphanDependents := false
for _ , replicaset := range replicasetList . Items {
deleteReplicaSetOrFail ( clientset , nsName , replicaset . Name , & orphanDependents )
}
}
// verifyCascadingDeletionForReplicaSet verifies that replicaSets are deleted
// from underlying clusters when orphan dependents is false and they are not
// deleted when orphan dependents is true.
func verifyCascadingDeletionForReplicaSet ( clientset * fedclientset . Clientset , clusters map [ string ] * cluster , orphanDependents * bool , nsName string ) {
2017-02-08 22:03:19 +00:00
replicaSet := createReplicaSetOrFail ( clientset , newReplicaSet ( nsName , FederationReplicaSetName , 5 , nil ) )
2016-11-10 01:50:25 +00:00
replicaSetName := replicaSet . Name
// Check subclusters if the replicaSet was created there.
By ( fmt . Sprintf ( "Waiting for replica sets %s to be created in all underlying clusters" , replicaSetName ) )
err := wait . Poll ( 5 * time . Second , 2 * time . Minute , func ( ) ( bool , error ) {
for _ , cluster := range clusters {
2016-12-07 14:40:26 +00:00
_ , err := cluster . Extensions ( ) . ReplicaSets ( nsName ) . Get ( replicaSetName , 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" )
By ( fmt . Sprintf ( "Deleting replica set %s" , replicaSetName ) )
deleteReplicaSetOrFail ( clientset , nsName , replicaSetName , orphanDependents )
By ( fmt . Sprintf ( "Verifying replica sets %s in underlying clusters" , replicaSetName ) )
errMessages := [ ] string { }
for clusterName , clusterClientset := range clusters {
2016-12-07 14:40:26 +00:00
_ , err := clusterClientset . Extensions ( ) . ReplicaSets ( nsName ) . Get ( replicaSetName , metav1 . GetOptions { } )
2016-11-10 01:50:25 +00:00
if ( orphanDependents == nil || * orphanDependents == true ) && errors . IsNotFound ( err ) {
errMessages = append ( errMessages , fmt . Sprintf ( "unexpected NotFound error for replica set %s in cluster %s, expected replica set to exist" , replicaSetName , clusterName ) )
} else if ( orphanDependents != nil && * orphanDependents == false ) && ( err == nil || ! errors . IsNotFound ( err ) ) {
errMessages = append ( errMessages , fmt . Sprintf ( "expected NotFound error for replica set %s in cluster %s, got error: %v" , replicaSetName , clusterName , err ) )
}
}
if len ( errMessages ) != 0 {
framework . Failf ( "%s" , strings . Join ( errMessages , "; " ) )
}
}
2017-02-08 22:03:19 +00:00
func generageFedRsPrefsWithWeight ( clusters map [ string ] * cluster ) ( pref * federation . FederatedReplicaSetPreferences , replicas int32 , expect map [ string ] int32 ) {
clusterNames := extraceClusterNames ( clusters )
pref = & federation . FederatedReplicaSetPreferences {
Clusters : map [ string ] federation . ClusterReplicaSetPreferences { } ,
}
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
clusterRsPref := pref . Clusters [ clusterName ]
clusterRsPref . Weight = int64 ( i )
replicas += int32 ( i )
expect [ clusterName ] = int32 ( i )
}
}
return
}
func generageFedRsPrefsWithMin ( clusters map [ string ] * cluster ) ( pref * federation . FederatedReplicaSetPreferences , replicas int32 , expect map [ string ] int32 ) {
clusterNames := extraceClusterNames ( clusters )
pref = & federation . FederatedReplicaSetPreferences {
Clusters : map [ string ] federation . ClusterReplicaSetPreferences {
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
clusterRsPref := pref . Clusters [ clusterName ]
clusterRsPref . Weight = int64 ( 1 )
clusterRsPref . MinReplicas = int64 ( i + 2 )
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
}
func generageFedRsPrefsWithMax ( clusters map [ string ] * cluster ) ( pref * federation . FederatedReplicaSetPreferences , replicas int32 , expect map [ string ] int32 ) {
clusterNames := extraceClusterNames ( clusters )
pref = & federation . FederatedReplicaSetPreferences {
Clusters : map [ string ] federation . ClusterReplicaSetPreferences {
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]
clusterRsPref := pref . Clusters [ clusterName ]
clusterRsPref . Weight = int64 ( 100 )
maxReplicas := int64 ( i )
clusterRsPref . MaxReplicas = & maxReplicas
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
}
func updateFedRePrefsRebalance ( pref * federation . FederatedReplicaSetPreferences , rebalance bool ) * federation . FederatedReplicaSetPreferences {
pref . Rebalance = rebalance
return pref
}
func generageFedRsPrefsForRebalancing ( clusters map [ string ] * cluster ) ( pref1 , pref2 * federation . FederatedReplicaSetPreferences , replicas int32 , expect1 , expect2 map [ string ] int32 ) {
clusterNames := extraceClusterNames ( clusters )
replicas = 3
pref1 = & federation . FederatedReplicaSetPreferences {
Clusters : map [ string ] federation . ClusterReplicaSetPreferences {
clusterNames [ 0 ] : { Weight : 1 } ,
clusterNames [ 1 ] : { Weight : 2 } ,
} ,
}
expect1 = map [ string ] int32 {
clusterNames [ 0 ] : 1 ,
clusterNames [ 1 ] : 2 ,
}
pref2 = & federation . FederatedReplicaSetPreferences {
Clusters : map [ string ] federation . ClusterReplicaSetPreferences {
clusterNames [ 0 ] : { Weight : 2 } ,
clusterNames [ 1 ] : { Weight : 1 } ,
} ,
}
expect2 = map [ string ] int32 {
clusterNames [ 0 ] : 2 ,
clusterNames [ 1 ] : 1 ,
}
return
}
func waitForReplicaSetOrFail ( c * fedclientset . Clientset , namespace string , replicaSetName string , clusters map [ string ] * cluster , expect map [ string ] int32 ) {
err := waitForReplicaSet ( c , namespace , replicaSetName , clusters , expect )
2016-11-10 01:50:25 +00:00
framework . ExpectNoError ( err , "Failed to verify replica set %q/%q, err: %v" , namespace , replicaSetName , err )
2016-09-01 19:36:54 +00:00
}
2017-02-08 22:03:19 +00:00
func waitForReplicaSet ( c * fedclientset . Clientset , namespace string , replicaSetName string , clusters map [ string ] * cluster , expect map [ string ] int32 ) error {
2016-09-01 19:36:54 +00:00
err := wait . Poll ( 10 * time . Second , FederatedReplicaSetTimeout , func ( ) ( bool , error ) {
2016-12-07 14:40:26 +00:00
frs , err := c . 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 {
2016-12-07 14:40:26 +00:00
rs , err := cluster . ReplicaSets ( namespace ) . Get ( replicaSetName , metav1 . GetOptions { } )
2016-09-01 19:36:54 +00:00
if err != nil && ! errors . IsNotFound ( err ) {
By ( fmt . Sprintf ( "Failed getting replicaset: %q/%q/%q, err: %v" , cluster . name , namespace , replicaSetName , err ) )
return false , err
}
2017-02-08 22:03:19 +00:00
if errors . IsNotFound ( err ) {
if expect != nil && expect [ cluster . name ] > 0 {
By ( fmt . Sprintf ( "Replicaset %q/%q/%q not created replicas: %v" , cluster . name , namespace , replicaSetName , expect [ cluster . name ] ) )
return false , nil
}
} else {
2016-09-01 19:36:54 +00:00
if ! equivalentReplicaSet ( frs , rs ) {
By ( fmt . Sprintf ( "Replicaset meta or spec not match for cluster %q:\n federation: %v\n cluster: %v" , cluster . name , frs , rs ) )
return false , nil
}
2017-02-08 22:03:19 +00:00
if expect != nil && * rs . Spec . Replicas < expect [ cluster . name ] {
By ( fmt . Sprintf ( "Replicas not match for %q/%q/%q: expect: >= %v, actual: %v" , cluster . name , namespace , replicaSetName , expect [ cluster . name ] , * rs . Spec . Replicas ) )
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 {
By ( fmt . Sprintf ( "ReplicaSet %q/%q with zero replicas should match the status as no overflow happens: expected: 0, actual: %v" , namespace , replicaSetName , frs . Status . Replicas ) )
return false , nil
}
2016-09-01 19:36:54 +00:00
if statusReplicas == frs . Status . Replicas && specReplicas >= * frs . Spec . Replicas {
return true , nil
}
By ( fmt . Sprintf ( "Replicas not match, federation replicas: %v/%v, clusters replicas: %v/%v\n" , * frs . Spec . Replicas , frs . Status . Replicas , specReplicas , statusReplicas ) )
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 ) )
}
By ( fmt . Sprintf ( "Creating federation replicaset %q in namespace %q" , FederationReplicaSetName , namespace ) )
2016-09-01 19:36:54 +00:00
_ , err := clientset . Extensions ( ) . ReplicaSets ( namespace ) . Create ( replicaset )
framework . ExpectNoError ( err , "Creating replicaset %q in namespace %q" , replicaset . Name , namespace )
By ( fmt . Sprintf ( "Successfully created federation replicaset %q in namespace %q" , FederationReplicaSetName , namespace ) )
return replicaset
}
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 ) )
}
By ( fmt . Sprintf ( "Updating federation replicaset %q in namespace %q" , FederationReplicaSetName , namespace ) )
newRs , err := clientset . ReplicaSets ( namespace ) . Update ( replicaset )
framework . ExpectNoError ( err , "Updating replicaset %q in namespace %q" , replicaset . Name , namespace )
By ( fmt . Sprintf ( "Successfully updated federation replicaset %q in namespace %q" , FederationReplicaSetName , namespace ) )
return newRs
}
2017-02-08 22:03:19 +00:00
func newReplicaSet ( namespace string , name string , replicas int32 , pref * federation . FederatedReplicaSetPreferences ) * v1beta1 . ReplicaSet {
rs := v1beta1 . ReplicaSet {
2017-01-17 03:38:19 +00:00
ObjectMeta : metav1 . ObjectMeta {
2017-02-08 22:03:19 +00:00
Name : name ,
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 {
2016-09-01 19:36:54 +00:00
MatchLabels : map [ string ] string { "name" : "myrs" } ,
} ,
2016-08-11 02:34:31 +00:00
Template : v1 . PodTemplateSpec {
2017-01-17 03:38:19 +00:00
ObjectMeta : metav1 . ObjectMeta {
2016-08-11 02:34:31 +00:00
Labels : map [ string ] string { "name" : "myrs" } ,
} ,
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 )
rs . Annotations [ fedreplicsetcontroller . FedReplicaSetPreferencesAnnotation ] = prefString
}
return & rs
}
func extraceClusterNames ( clusters map [ string ] * cluster ) [ ] string {
clusterNames := make ( [ ] string , 0 , len ( clusters ) )
for clusterName := range clusters {
clusterNames = append ( clusterNames , clusterName )
}
return clusterNames
2016-08-11 02:34:31 +00:00
}