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
d1e47a88
Commit
d1e47a88
authored
Mar 30, 2016
by
jianhuiz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
duplicate /cmd/kube-apiserver to /federation/cmd/federated-apiserver
parent
cd0caf53
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
425 additions
and
0 deletions
+425
-0
OWNERS
federation/cmd/federated-apiserver/OWNERS
+5
-0
apiserver.go
federation/cmd/federated-apiserver/apiserver.go
+54
-0
options.go
federation/cmd/federated-apiserver/app/options/options.go
+0
-0
options_test.go
...ation/cmd/federated-apiserver/app/options/options_test.go
+99
-0
plugins.go
federation/cmd/federated-apiserver/app/plugins.go
+40
-0
server.go
federation/cmd/federated-apiserver/app/server.go
+0
-0
server_test.go
federation/cmd/federated-apiserver/app/server_test.go
+227
-0
No files found.
federation/cmd/federated-apiserver/OWNERS
0 → 100644
View file @
d1e47a88
assignees:
- lavalamp
- smarterclayton
- nikhiljindal
- krousey
federation/cmd/federated-apiserver/apiserver.go
0 → 100644
View file @
d1e47a88
/*
Copyright 2014 The Kubernetes Authors All rights reserved.
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.
*/
// apiserver is the main api server and master for the cluster.
// it is responsible for serving the cluster management API.
package
main
import
(
"fmt"
"math/rand"
"os"
"runtime"
"time"
"k8s.io/kubernetes/cmd/kube-apiserver/app"
"k8s.io/kubernetes/cmd/kube-apiserver/app/options"
"k8s.io/kubernetes/pkg/util"
"k8s.io/kubernetes/pkg/util/flag"
"k8s.io/kubernetes/pkg/version/verflag"
"github.com/spf13/pflag"
)
func
main
()
{
runtime
.
GOMAXPROCS
(
runtime
.
NumCPU
())
rand
.
Seed
(
time
.
Now
()
.
UTC
()
.
UnixNano
())
s
:=
options
.
NewAPIServer
()
s
.
AddFlags
(
pflag
.
CommandLine
)
flag
.
InitFlags
()
util
.
InitLogs
()
defer
util
.
FlushLogs
()
verflag
.
PrintAndExitIfRequested
()
if
err
:=
app
.
Run
(
s
);
err
!=
nil
{
fmt
.
Fprintf
(
os
.
Stderr
,
"%v
\n
"
,
err
)
os
.
Exit
(
1
)
}
}
federation/cmd/federated-apiserver/app/options/options.go
0 → 100644
View file @
d1e47a88
This diff is collapsed.
Click to expand it.
federation/cmd/federated-apiserver/app/options/options_test.go
0 → 100644
View file @
d1e47a88
/*
Copyright 2014 The Kubernetes Authors All rights reserved.
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.
*/
package
options
import
(
"reflect"
"testing"
"github.com/spf13/pflag"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/apis/autoscaling"
"k8s.io/kubernetes/pkg/apis/extensions"
)
func
TestGenerateStorageVersionMap
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
legacyVersion
string
storageVersions
string
defaultVersions
string
expectedMap
map
[
string
]
string
}{
{
legacyVersion
:
"v1"
,
storageVersions
:
"v1,extensions/v1beta1"
,
expectedMap
:
map
[
string
]
string
{
api
.
GroupName
:
"v1"
,
extensions
.
GroupName
:
"extensions/v1beta1"
,
},
},
{
legacyVersion
:
""
,
storageVersions
:
"extensions/v1beta1,v1"
,
expectedMap
:
map
[
string
]
string
{
api
.
GroupName
:
"v1"
,
extensions
.
GroupName
:
"extensions/v1beta1"
,
},
},
{
legacyVersion
:
""
,
storageVersions
:
"autoscaling=extensions/v1beta1,v1"
,
defaultVersions
:
"extensions/v1beta1,v1,autoscaling/v1"
,
expectedMap
:
map
[
string
]
string
{
api
.
GroupName
:
"v1"
,
autoscaling
.
GroupName
:
"extensions/v1beta1"
,
extensions
.
GroupName
:
"extensions/v1beta1"
,
},
},
{
legacyVersion
:
""
,
storageVersions
:
""
,
expectedMap
:
map
[
string
]
string
{},
},
}
for
i
,
test
:=
range
testCases
{
s
:=
APIServer
{
DeprecatedStorageVersion
:
test
.
legacyVersion
,
StorageVersions
:
test
.
storageVersions
,
DefaultStorageVersions
:
test
.
defaultVersions
,
}
output
:=
s
.
StorageGroupsToGroupVersions
()
if
!
reflect
.
DeepEqual
(
test
.
expectedMap
,
output
)
{
t
.
Errorf
(
"%v: unexpected error. expect: %v, got: %v"
,
i
,
test
.
expectedMap
,
output
)
}
}
}
func
TestAddFlagsFlag
(
t
*
testing
.
T
)
{
// TODO: This only tests the enable-swagger-ui flag for now.
// Expand the test to include other flags as well.
f
:=
pflag
.
NewFlagSet
(
"addflagstest"
,
pflag
.
ContinueOnError
)
s
:=
NewAPIServer
()
s
.
AddFlags
(
f
)
if
s
.
EnableSwaggerUI
{
t
.
Errorf
(
"Expected s.EnableSwaggerUI to be false by default"
)
}
args
:=
[]
string
{
"--enable-swagger-ui=true"
,
}
f
.
Parse
(
args
)
if
!
s
.
EnableSwaggerUI
{
t
.
Errorf
(
"Expected s.EnableSwaggerUI to be true"
)
}
}
federation/cmd/federated-apiserver/app/plugins.go
0 → 100644
View file @
d1e47a88
/*
Copyright 2014 The Kubernetes Authors All rights reserved.
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.
*/
package
app
// This file exists to force the desired plugin implementations to be linked.
// This should probably be part of some configuration fed into the build for a
// given binary target.
import
(
// Cloud providers
_
"k8s.io/kubernetes/pkg/cloudprovider/providers"
// Admission policies
_
"k8s.io/kubernetes/plugin/pkg/admission/admit"
_
"k8s.io/kubernetes/plugin/pkg/admission/alwayspullimages"
_
"k8s.io/kubernetes/plugin/pkg/admission/deny"
_
"k8s.io/kubernetes/plugin/pkg/admission/exec"
_
"k8s.io/kubernetes/plugin/pkg/admission/initialresources"
_
"k8s.io/kubernetes/plugin/pkg/admission/limitranger"
_
"k8s.io/kubernetes/plugin/pkg/admission/namespace/autoprovision"
_
"k8s.io/kubernetes/plugin/pkg/admission/namespace/exists"
_
"k8s.io/kubernetes/plugin/pkg/admission/namespace/lifecycle"
_
"k8s.io/kubernetes/plugin/pkg/admission/persistentvolume/label"
_
"k8s.io/kubernetes/plugin/pkg/admission/resourcequota"
_
"k8s.io/kubernetes/plugin/pkg/admission/securitycontext/scdeny"
_
"k8s.io/kubernetes/plugin/pkg/admission/serviceaccount"
)
federation/cmd/federated-apiserver/app/server.go
0 → 100644
View file @
d1e47a88
This diff is collapsed.
Click to expand it.
federation/cmd/federated-apiserver/app/server_test.go
0 → 100644
View file @
d1e47a88
/*
Copyright 2015 The Kubernetes Authors All rights reserved.
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.
*/
package
app
import
(
"reflect"
"regexp"
"strings"
"testing"
"k8s.io/kubernetes/cmd/kube-apiserver/app/options"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/unversioned"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/genericapiserver"
"k8s.io/kubernetes/pkg/master"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/storage"
etcdstorage
"k8s.io/kubernetes/pkg/storage/etcd"
)
func
TestLongRunningRequestRegexp
(
t
*
testing
.
T
)
{
regexp
:=
regexp
.
MustCompile
(
options
.
NewAPIServer
()
.
LongRunningRequestRE
)
dontMatch
:=
[]
string
{
"/api/v1/watch-namespace/"
,
"/api/v1/namespace-proxy/"
,
"/api/v1/namespace-watch"
,
"/api/v1/namespace-proxy"
,
"/api/v1/namespace-portforward/pods"
,
"/api/v1/portforward/pods"
,
". anything"
,
"/ that"
,
}
doMatch
:=
[]
string
{
"/api/v1/pods/watch"
,
"/api/v1/watch/stuff"
,
"/api/v1/default/service/proxy"
,
"/api/v1/pods/proxy/path/to/thing"
,
"/api/v1/namespaces/myns/pods/mypod/log"
,
"/api/v1/namespaces/myns/pods/mypod/logs"
,
"/api/v1/namespaces/myns/pods/mypod/portforward"
,
"/api/v1/namespaces/myns/pods/mypod/exec"
,
"/api/v1/namespaces/myns/pods/mypod/attach"
,
"/api/v1/namespaces/myns/pods/mypod/log/"
,
"/api/v1/namespaces/myns/pods/mypod/logs/"
,
"/api/v1/namespaces/myns/pods/mypod/portforward/"
,
"/api/v1/namespaces/myns/pods/mypod/exec/"
,
"/api/v1/namespaces/myns/pods/mypod/attach/"
,
"/api/v1/watch/namespaces/myns/pods"
,
}
for
_
,
path
:=
range
dontMatch
{
if
regexp
.
MatchString
(
path
)
{
t
.
Errorf
(
"path should not have match regexp but did: %s"
,
path
)
}
}
for
_
,
path
:=
range
doMatch
{
if
!
regexp
.
MatchString
(
path
)
{
t
.
Errorf
(
"path should have match regexp did not: %s"
,
path
)
}
}
}
func
TestUpdateEtcdOverrides
(
t
*
testing
.
T
)
{
storageVersions
:=
map
[
string
]
string
{
""
:
"v1"
,
"extensions"
:
"extensions/v1beta1"
,
}
testCases
:=
[]
struct
{
apigroup
string
resource
string
servers
[]
string
}{
{
apigroup
:
api
.
GroupName
,
resource
:
"resource"
,
servers
:
[]
string
{
"http://127.0.0.1:10000"
},
},
{
apigroup
:
api
.
GroupName
,
resource
:
"resource"
,
servers
:
[]
string
{
"http://127.0.0.1:10000"
,
"http://127.0.0.1:20000"
},
},
{
apigroup
:
extensions
.
GroupName
,
resource
:
"resource"
,
servers
:
[]
string
{
"http://127.0.0.1:10000"
},
},
}
for
_
,
test
:=
range
testCases
{
newEtcd
:=
func
(
_
runtime
.
NegotiatedSerializer
,
_
,
_
string
,
etcdConfig
etcdstorage
.
EtcdConfig
)
(
storage
.
Interface
,
error
)
{
if
!
reflect
.
DeepEqual
(
test
.
servers
,
etcdConfig
.
ServerList
)
{
t
.
Errorf
(
"unexpected server list, expected: %#v, got: %#v"
,
test
.
servers
,
etcdConfig
.
ServerList
)
}
return
nil
,
nil
}
storageDestinations
:=
genericapiserver
.
NewStorageDestinations
()
override
:=
test
.
apigroup
+
"/"
+
test
.
resource
+
"#"
+
strings
.
Join
(
test
.
servers
,
";"
)
defaultEtcdConfig
:=
etcdstorage
.
EtcdConfig
{
Prefix
:
genericapiserver
.
DefaultEtcdPathPrefix
,
ServerList
:
[]
string
{
"http://127.0.0.1"
},
}
updateEtcdOverrides
([]
string
{
override
},
storageVersions
,
defaultEtcdConfig
,
&
storageDestinations
,
newEtcd
)
apigroup
,
ok
:=
storageDestinations
.
APIGroups
[
test
.
apigroup
]
if
!
ok
{
t
.
Errorf
(
"apigroup: %s not created"
,
test
.
apigroup
)
continue
}
if
apigroup
.
Overrides
==
nil
{
t
.
Errorf
(
"Overrides not created for: %s"
,
test
.
apigroup
)
continue
}
if
_
,
ok
:=
apigroup
.
Overrides
[
test
.
resource
];
!
ok
{
t
.
Errorf
(
"override not created for: %s"
,
test
.
resource
)
continue
}
}
}
func
TestParseRuntimeConfig
(
t
*
testing
.
T
)
{
testCases
:=
[]
struct
{
runtimeConfig
map
[
string
]
string
expectedAPIConfig
func
()
*
genericapiserver
.
ResourceConfig
err
bool
}{
{
runtimeConfig
:
map
[
string
]
string
{},
expectedAPIConfig
:
func
()
*
genericapiserver
.
ResourceConfig
{
return
master
.
DefaultAPIResourceConfigSource
()
},
err
:
false
,
},
{
// Cannot override v1 resources.
runtimeConfig
:
map
[
string
]
string
{
"api/v1/pods"
:
"false"
,
},
expectedAPIConfig
:
func
()
*
genericapiserver
.
ResourceConfig
{
return
master
.
DefaultAPIResourceConfigSource
()
},
err
:
true
,
},
{
// Disable v1.
runtimeConfig
:
map
[
string
]
string
{
"api/v1"
:
"false"
,
},
expectedAPIConfig
:
func
()
*
genericapiserver
.
ResourceConfig
{
config
:=
master
.
DefaultAPIResourceConfigSource
()
config
.
DisableVersions
(
unversioned
.
GroupVersion
{
Group
:
""
,
Version
:
"v1"
})
return
config
},
err
:
false
,
},
{
// Disable extensions.
runtimeConfig
:
map
[
string
]
string
{
"extensions/v1beta1"
:
"false"
,
},
expectedAPIConfig
:
func
()
*
genericapiserver
.
ResourceConfig
{
config
:=
master
.
DefaultAPIResourceConfigSource
()
config
.
DisableVersions
(
unversioned
.
GroupVersion
{
Group
:
"extensions"
,
Version
:
"v1beta1"
})
return
config
},
err
:
false
,
},
{
// Disable deployments.
runtimeConfig
:
map
[
string
]
string
{
"extensions/v1beta1/deployments"
:
"false"
,
},
expectedAPIConfig
:
func
()
*
genericapiserver
.
ResourceConfig
{
config
:=
master
.
DefaultAPIResourceConfigSource
()
config
.
DisableResources
(
unversioned
.
GroupVersionResource
{
Group
:
"extensions"
,
Version
:
"v1beta1"
,
Resource
:
"deployments"
})
return
config
},
err
:
false
,
},
{
// Enable deployments and disable jobs.
runtimeConfig
:
map
[
string
]
string
{
"extensions/v1beta1/anything"
:
"true"
,
"extensions/v1beta1/jobs"
:
"false"
,
},
expectedAPIConfig
:
func
()
*
genericapiserver
.
ResourceConfig
{
config
:=
master
.
DefaultAPIResourceConfigSource
()
config
.
DisableResources
(
unversioned
.
GroupVersionResource
{
Group
:
"extensions"
,
Version
:
"v1beta1"
,
Resource
:
"jobs"
})
config
.
EnableResources
(
unversioned
.
GroupVersionResource
{
Group
:
"extensions"
,
Version
:
"v1beta1"
,
Resource
:
"anything"
})
return
config
},
err
:
false
,
},
}
for
_
,
test
:=
range
testCases
{
s
:=
&
options
.
APIServer
{
RuntimeConfig
:
test
.
runtimeConfig
,
}
actualDisablers
,
err
:=
parseRuntimeConfig
(
s
)
if
err
==
nil
&&
test
.
err
{
t
.
Fatalf
(
"expected error for test: %v"
,
test
)
}
else
if
err
!=
nil
&&
!
test
.
err
{
t
.
Fatalf
(
"unexpected error: %s, for test: %v"
,
err
,
test
)
}
expectedConfig
:=
test
.
expectedAPIConfig
()
if
err
==
nil
&&
!
reflect
.
DeepEqual
(
actualDisablers
,
expectedConfig
)
{
t
.
Fatalf
(
"%v: unexpected apiResourceDisablers. Actual: %q
\n
expected: %q"
,
test
.
runtimeConfig
,
actualDisablers
,
expectedConfig
)
}
}
}
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