@@ -2,29 +2,18 @@ package lifecycle
2
2
3
3
import (
4
4
"fmt"
5
- "strings"
6
5
"testing"
7
- "time"
8
6
9
7
"k8s.io/kubernetes/pkg/admission"
10
8
kapi "k8s.io/kubernetes/pkg/api"
11
9
"k8s.io/kubernetes/pkg/api/unversioned"
12
10
"k8s.io/kubernetes/pkg/client/cache"
13
11
clientsetfake "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset/fake"
14
12
"k8s.io/kubernetes/pkg/client/unversioned/testclient"
15
- genericapiserveroptions "k8s.io/kubernetes/pkg/genericapiserver/options"
16
- kubeletclient "k8s.io/kubernetes/pkg/kubelet/client"
17
13
"k8s.io/kubernetes/pkg/runtime"
18
- etcdstorage "k8s.io/kubernetes/pkg/storage/etcd"
19
- "k8s.io/kubernetes/pkg/util/sets"
20
14
21
15
buildapi "github.com/openshift/origin/pkg/build/api"
22
- otestclient "github.com/openshift/origin/pkg/client/testclient"
23
- "github.com/openshift/origin/pkg/cmd/server/origin"
24
- "github.com/openshift/origin/pkg/controller/shared"
25
16
projectcache "github.com/openshift/origin/pkg/project/cache"
26
- "github.com/openshift/origin/pkg/quota/controller/clusterquotamapping"
27
- "github.com/openshift/origin/pkg/util/restoptions"
28
17
29
18
// install all APIs
30
19
_ "github.com/openshift/origin/pkg/api/install"
@@ -90,105 +79,6 @@ func TestAdmissionExists(t *testing.T) {
90
79
}
91
80
}
92
81
93
- // TestAdmissionLifecycle verifies you cannot create Origin content if namespace is terminating
94
- func TestAdmissionLifecycle (t * testing.T ) {
95
- namespaceObj := & kapi.Namespace {
96
- ObjectMeta : kapi.ObjectMeta {
97
- Name : "test" ,
98
- Namespace : "" ,
99
- },
100
- Status : kapi.NamespaceStatus {
101
- Phase : kapi .NamespaceActive ,
102
- },
103
- }
104
- store := projectcache .NewCacheStore (cache .IndexFuncToKeyFuncAdapter (cache .MetaNamespaceIndexFunc ))
105
- store .Add (namespaceObj )
106
- mockClient := & testclient.Fake {}
107
- cache := projectcache .NewFake (mockClient .Namespaces (), store , "" )
108
-
109
- mockClientset := clientsetfake .NewSimpleClientset (namespaceObj )
110
- handler := & lifecycle {client : mockClientset }
111
- handler .SetProjectCache (cache )
112
- build := & buildapi.Build {
113
- ObjectMeta : kapi.ObjectMeta {Name : "buildid" , Namespace : "other" },
114
- Spec : buildapi.BuildSpec {
115
- CommonSpec : buildapi.CommonSpec {
116
- Source : buildapi.BuildSource {
117
- Git : & buildapi.GitBuildSource {
118
- URI : "http://github.com/my/repository" ,
119
- },
120
- ContextDir : "context" ,
121
- },
122
- Strategy : buildapi.BuildStrategy {
123
- DockerStrategy : & buildapi.DockerBuildStrategy {},
124
- },
125
- Output : buildapi.BuildOutput {
126
- To : & kapi.ObjectReference {
127
- Kind : "DockerImage" ,
128
- Name : "repository/data" ,
129
- },
130
- },
131
- },
132
- },
133
- Status : buildapi.BuildStatus {
134
- Phase : buildapi .BuildPhaseNew ,
135
- },
136
- }
137
- err := handler .Admit (admission .NewAttributesRecord (build , nil , kapi .Kind ("Build" ).WithVersion ("version" ), build .Namespace , "name" , kapi .Resource ("builds" ).WithVersion ("version" ), "" , "CREATE" , nil ))
138
- if err != nil {
139
- t .Errorf ("Unexpected error returned from admission handler: %v" , err )
140
- }
141
-
142
- // change namespace state to terminating
143
- namespaceObj .Status .Phase = kapi .NamespaceTerminating
144
- store .Add (namespaceObj )
145
-
146
- // verify create operations in the namespace cause an error
147
- err = handler .Admit (admission .NewAttributesRecord (build , nil , kapi .Kind ("Build" ).WithVersion ("version" ), build .Namespace , "name" , kapi .Resource ("builds" ).WithVersion ("version" ), "" , "CREATE" , nil ))
148
- if err == nil {
149
- t .Errorf ("Expected error rejecting creates in a namespace when it is terminating" )
150
- }
151
-
152
- // verify update operations in the namespace can proceed
153
- err = handler .Admit (admission .NewAttributesRecord (build , build , kapi .Kind ("Build" ).WithVersion ("version" ), build .Namespace , "name" , kapi .Resource ("builds" ).WithVersion ("version" ), "" , "UPDATE" , nil ))
154
- if err != nil {
155
- t .Errorf ("Unexpected error returned from admission handler: %v" , err )
156
- }
157
-
158
- // verify delete operations in the namespace can proceed
159
- err = handler .Admit (admission .NewAttributesRecord (nil , nil , kapi .Kind ("Build" ).WithVersion ("version" ), build .Namespace , "name" , kapi .Resource ("builds" ).WithVersion ("version" ), "" , "DELETE" , nil ))
160
- if err != nil {
161
- t .Errorf ("Unexpected error returned from admission handler: %v" , err )
162
- }
163
-
164
- }
165
-
166
- // TestCreatesAllowedDuringNamespaceDeletion checks to make sure that the resources in the whitelist are allowed
167
- func TestCreatesAllowedDuringNamespaceDeletion (t * testing.T ) {
168
- etcdHelper := etcdstorage .NewEtcdStorage (nil , kapi .Codecs .LegacyCodec (), "" , false , genericapiserveroptions .DefaultDeserializationCacheSize )
169
-
170
- informerFactory := shared .NewInformerFactory (testclient .NewSimpleFake (), otestclient .NewSimpleFake (), shared.DefaultListerWatcherOverrides {}, 1 * time .Second )
171
- config := & origin.MasterConfig {
172
- KubeletClientConfig : & kubeletclient.KubeletClientConfig {},
173
- RESTOptionsGetter : restoptions .NewSimpleGetter (etcdHelper ),
174
- EtcdHelper : etcdHelper ,
175
- Informers : informerFactory ,
176
- ClusterQuotaMappingController : clusterquotamapping .NewClusterQuotaMappingController (informerFactory .Namespaces (), informerFactory .ClusterResourceQuotas ()),
177
- }
178
- storageMap := config .GetRestStorage ()
179
- resources := sets.String {}
180
-
181
- for resource := range storageMap {
182
- resources .Insert (strings .ToLower (resource ))
183
- }
184
-
185
- for resource := range recommendedCreatableResources {
186
- if ! resources .Has (resource ) {
187
- t .Errorf ("recommendedCreatableResources has resource %v, but that resource isn't registered." , resource )
188
- }
189
- }
190
- }
191
-
192
82
func TestSAR (t * testing.T ) {
193
83
store := projectcache .NewCacheStore (cache .IndexFuncToKeyFuncAdapter (cache .MetaNamespaceIndexFunc ))
194
84
mockClient := & testclient.Fake {}
0 commit comments