Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
a2e6542e
Commit
a2e6542e
authored
Sep 01, 2016
by
jianhuiz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update e2e test for federation replicaset controlelr
parent
f673bc88
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
119 additions
and
10 deletions
+119
-10
federation-replicaset.go
test/e2e/federation-replicaset.go
+119
-10
No files found.
test/e2e/federation-replicaset.go
View file @
a2e6542e
...
@@ -18,19 +18,26 @@ package e2e
...
@@ -18,19 +18,26 @@ package e2e
import
(
import
(
"fmt"
"fmt"
"os"
"time"
.
"github.com/onsi/ginkgo"
"k8s.io/kubernetes/federation/client/clientset_generated/federation_release_1_4"
"k8s.io/kubernetes/federation/client/clientset_generated/federation_release_1_4"
fedutil
"k8s.io/kubernetes/federation/pkg/federation-controller/util"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
"k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
"k8s.io/kubernetes/pkg/util/wait"
"k8s.io/kubernetes/test/e2e/framework"
"k8s.io/kubernetes/test/e2e/framework"
.
"github.com/onsi/ginkgo"
.
"github.com/onsi/gomega"
.
"github.com/onsi/gomega"
"k8s.io/kubernetes/pkg/api/errors"
"reflect"
)
)
const
(
const
(
FederationReplicaSetName
=
"federation-replicaset"
FederationReplicaSetName
=
"federation-replicaset"
FederatedReplicaSetTimeout
=
120
*
time
.
Second
)
)
// Create/delete replicaset api objects
// Create/delete replicaset api objects
...
@@ -64,22 +71,129 @@ var _ = framework.KubeDescribe("Federation replicasets [Feature:Federation]", fu
...
@@ -64,22 +71,129 @@ var _ = framework.KubeDescribe("Federation replicasets [Feature:Federation]", fu
})
})
})
})
// e2e cases for federated replicaset controller
Describe
(
"Federated ReplicaSet"
,
func
()
{
var
(
clusters
map
[
string
]
*
cluster
federationName
string
)
BeforeEach
(
func
()
{
framework
.
SkipUnlessFederated
(
f
.
Client
)
if
federationName
=
os
.
Getenv
(
"FEDERATION_NAME"
);
federationName
==
""
{
federationName
=
DefaultFederationName
}
registerClusters
(
clusters
,
UserAgentName
,
federationName
,
f
)
})
AfterEach
(
func
()
{
unregisterClusters
(
clusters
,
f
)
})
It
(
"should create and update matching replicasets in underling clusters"
,
func
()
{
rs
:=
createReplicaSetOrFail
(
f
.
FederationClientset_1_4
,
f
.
Namespace
.
Namespace
)
defer
func
()
{
// cleanup. deletion of replicasets is not supported for underling clusters
By
(
fmt
.
Sprintf
(
"zero replicas then delete replicaset %q/%q"
,
f
.
Namespace
.
Name
,
rs
.
Name
))
replicas
:=
int32
(
0
)
rs
.
Spec
.
Replicas
=
&
replicas
f
.
FederationClientset_1_4
.
ReplicaSets
(
f
.
Namespace
.
Name
)
.
Update
(
rs
)
waitForReplicaSetOrFail
(
f
.
FederationClientset_1_4
,
f
.
Namespace
.
Name
,
rs
.
Name
,
clusters
)
f
.
FederationClientset_1_4
.
ReplicaSets
(
f
.
Namespace
.
Name
)
.
Delete
(
rs
.
Name
,
&
api
.
DeleteOptions
{})
}()
waitForReplicaSetOrFail
(
f
.
FederationClientset_1_4
,
f
.
Namespace
.
Name
,
rs
.
Name
,
clusters
)
By
(
fmt
.
Sprintf
(
"Successfuly created and synced replicaset %q/%q to clusters"
,
f
.
Namespace
.
Namespace
,
rs
.
Name
))
updateReplicaSetOrFail
(
f
.
FederationClientset_1_4
,
f
.
Namespace
.
Namespace
)
waitForReplicaSetOrFail
(
f
.
FederationClientset_1_4
,
f
.
Namespace
.
Name
,
rs
.
Name
,
clusters
)
By
(
fmt
.
Sprintf
(
"Successfuly updated and synced replicaset %q/%q to clusters"
,
f
.
Namespace
.
Namespace
,
rs
.
Name
))
})
})
})
})
func
waitForReplicaSetOrFail
(
c
*
federation_release_1_4
.
Clientset
,
namespace
string
,
replicaSetName
string
,
clusters
map
[
string
]
*
cluster
)
{
err
:=
waitForReplicaSet
(
c
,
namespace
,
replicaSetName
,
clusters
)
framework
.
ExpectNoError
(
err
,
"Failed to verify replicaset %q/%q, err: %v"
,
namespace
,
replicaSetName
,
err
)
}
func
waitForReplicaSet
(
c
*
federation_release_1_4
.
Clientset
,
namespace
string
,
replicaSetName
string
,
clusters
map
[
string
]
*
cluster
)
error
{
err
:=
wait
.
Poll
(
10
*
time
.
Second
,
FederatedReplicaSetTimeout
,
func
()
(
bool
,
error
)
{
frs
,
err
:=
c
.
ReplicaSets
(
namespace
)
.
Get
(
replicaSetName
)
if
err
!=
nil
{
return
false
,
err
}
specReplicas
,
statusReplicas
:=
int32
(
0
),
int32
(
0
)
for
_
,
cluster
:=
range
clusters
{
rs
,
err
:=
cluster
.
ReplicaSets
(
namespace
)
.
Get
(
replicaSetName
)
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
}
if
err
==
nil
{
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
}
specReplicas
+=
*
rs
.
Spec
.
Replicas
statusReplicas
+=
rs
.
Status
.
Replicas
}
}
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
)
}
func
createReplicaSetOrFail
(
clientset
*
federation_release_1_4
.
Clientset
,
namespace
string
)
*
v1beta1
.
ReplicaSet
{
func
createReplicaSetOrFail
(
clientset
*
federation_release_1_4
.
Clientset
,
namespace
string
)
*
v1beta1
.
ReplicaSet
{
if
clientset
==
nil
||
len
(
namespace
)
==
0
{
if
clientset
==
nil
||
len
(
namespace
)
==
0
{
Fail
(
fmt
.
Sprintf
(
"Internal error: invalid parameters passed to createReplicaSetOrFail: clientset: %v, namespace: %v"
,
clientset
,
namespace
))
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
))
By
(
fmt
.
Sprintf
(
"Creating federation replicaset %q in namespace %q"
,
FederationReplicaSetName
,
namespace
))
replicas
:=
int32
(
5
)
replicaset
:=
newReplicaSet
(
namespace
,
FederationReplicaSetName
,
5
)
replicaset
:=
&
v1beta1
.
ReplicaSet
{
_
,
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
}
func
updateReplicaSetOrFail
(
clientset
*
federation_release_1_4
.
Clientset
,
namespace
string
)
*
v1beta1
.
ReplicaSet
{
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
))
replicaset
:=
newReplicaSet
(
namespace
,
FederationReplicaSetName
,
15
)
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
}
func
newReplicaSet
(
namespace
string
,
name
string
,
replicas
int32
)
*
v1beta1
.
ReplicaSet
{
return
&
v1beta1
.
ReplicaSet
{
ObjectMeta
:
v1
.
ObjectMeta
{
ObjectMeta
:
v1
.
ObjectMeta
{
Name
:
FederationReplicaSetN
ame
,
Name
:
n
ame
,
Namespace
:
namespace
,
Namespace
:
namespace
,
},
},
Spec
:
v1beta1
.
ReplicaSetSpec
{
Spec
:
v1beta1
.
ReplicaSetSpec
{
Replicas
:
&
replicas
,
Replicas
:
&
replicas
,
Selector
:
&
v1beta1
.
LabelSelector
{
MatchLabels
:
map
[
string
]
string
{
"name"
:
"myrs"
},
},
Template
:
v1
.
PodTemplateSpec
{
Template
:
v1
.
PodTemplateSpec
{
ObjectMeta
:
v1
.
ObjectMeta
{
ObjectMeta
:
v1
.
ObjectMeta
{
Labels
:
map
[
string
]
string
{
"name"
:
"myrs"
},
Labels
:
map
[
string
]
string
{
"name"
:
"myrs"
},
...
@@ -95,9 +209,4 @@ func createReplicaSetOrFail(clientset *federation_release_1_4.Clientset, namespa
...
@@ -95,9 +209,4 @@ func createReplicaSetOrFail(clientset *federation_release_1_4.Clientset, namespa
},
},
},
},
}
}
_
,
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
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment