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
f96fa748
Commit
f96fa748
authored
Jan 04, 2017
by
Dr. Stefan Schimanski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move apiserver cloudprovider dep into kubeapiserver
parent
5e9f39b5
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
103 additions
and
55 deletions
+103
-55
options.go
cmd/kube-apiserver/app/options/options.go
+3
-0
server.go
cmd/kube-apiserver/app/server.go
+2
-2
apiserver.go
examples/apiserver/apiserver.go
+3
-1
options.go
federation/cmd/federation-apiserver/app/options/options.go
+3
-0
server.go
federation/cmd/federation-apiserver/app/server.go
+1
-1
BUILD
pkg/genericapiserver/options/BUILD
+0
-2
server_run_options.go
pkg/genericapiserver/options/server_run_options.go
+0
-49
BUILD
pkg/kubeapiserver/options/BUILD
+3
-0
cloudprovider.go
pkg/kubeapiserver/options/cloudprovider.go
+88
-0
No files found.
cmd/kube-apiserver/app/options/options.go
View file @
f96fa748
...
...
@@ -43,6 +43,7 @@ type ServerRunOptions struct {
InsecureServing
*
genericoptions
.
ServingOptions
Authentication
*
kubeoptions
.
BuiltInAuthenticationOptions
Authorization
*
kubeoptions
.
BuiltInAuthorizationOptions
CloudProvider
*
kubeoptions
.
CloudProviderOptions
AllowPrivileged
bool
EventTTL
time
.
Duration
...
...
@@ -65,6 +66,7 @@ func NewServerRunOptions() *ServerRunOptions {
InsecureServing
:
genericoptions
.
NewInsecureServingOptions
(),
Authentication
:
kubeoptions
.
NewBuiltInAuthenticationOptions
()
.
WithAll
(),
Authorization
:
kubeoptions
.
NewBuiltInAuthorizationOptions
(),
CloudProvider
:
kubeoptions
.
NewCloudProviderOptions
(),
EventTTL
:
1
*
time
.
Hour
,
MasterCount
:
1
,
...
...
@@ -96,6 +98,7 @@ func (s *ServerRunOptions) AddFlags(fs *pflag.FlagSet) {
s
.
InsecureServing
.
AddDeprecatedFlags
(
fs
)
s
.
Authentication
.
AddFlags
(
fs
)
s
.
Authorization
.
AddFlags
(
fs
)
s
.
CloudProvider
.
AddFlags
(
fs
)
// Note: the weird ""+ in below lines seems to be the only way to get gofmt to
// arrange these text blocks sensibly. Grrr.
...
...
cmd/kube-apiserver/app/server.go
View file @
f96fa748
...
...
@@ -90,7 +90,7 @@ func Run(s *options.ServerRunOptions) error {
if
err
:=
s
.
SecureServing
.
MaybeDefaultWithSelfSignedCerts
(
s
.
GenericServerRunOptions
.
AdvertiseAddress
.
String
(),
apiServerServiceIP
);
err
!=
nil
{
return
fmt
.
Errorf
(
"error creating self-signed certificates: %v"
,
err
)
}
if
err
:=
s
.
GenericServerRunOptions
.
DefaultExternalHost
(
);
err
!=
nil
{
if
err
:=
s
.
CloudProvider
.
DefaultExternalHost
(
s
.
GenericServerRunOptions
);
err
!=
nil
{
return
fmt
.
Errorf
(
"error setting the external host value: %v"
,
err
)
}
...
...
@@ -128,7 +128,7 @@ func Run(s *options.ServerRunOptions) error {
if
len
(
s
.
SSHUser
)
>
0
{
// Get ssh key distribution func, if supported
var
installSSH
genericapiserver
.
InstallSSHKey
cloud
,
err
:=
cloudprovider
.
InitCloudProvider
(
s
.
GenericServerRunOptions
.
CloudProvider
,
s
.
GenericServerRunOptions
.
CloudConfigFile
)
cloud
,
err
:=
cloudprovider
.
InitCloudProvider
(
s
.
CloudProvider
.
CloudProvider
,
s
.
CloudProvider
.
CloudConfigFile
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"cloud provider could not be initialized: %v"
,
err
)
}
...
...
examples/apiserver/apiserver.go
View file @
f96fa748
...
...
@@ -62,6 +62,7 @@ type ServerRunOptions struct {
SecureServing
*
genericoptions
.
SecureServingOptions
InsecureServing
*
genericoptions
.
ServingOptions
Authentication
*
kubeoptions
.
BuiltInAuthenticationOptions
CloudProvider
*
kubeoptions
.
CloudProviderOptions
}
func
NewServerRunOptions
()
*
ServerRunOptions
{
...
...
@@ -71,6 +72,7 @@ func NewServerRunOptions() *ServerRunOptions {
SecureServing
:
genericoptions
.
NewSecureServingOptions
(),
InsecureServing
:
genericoptions
.
NewInsecureServingOptions
(),
Authentication
:
kubeoptions
.
NewBuiltInAuthenticationOptions
()
.
WithAll
(),
CloudProvider
:
kubeoptions
.
NewCloudProviderOptions
(),
}
s
.
InsecureServing
.
BindPort
=
InsecurePort
s
.
SecureServing
.
ServingOptions
.
BindPort
=
SecurePort
...
...
@@ -82,7 +84,7 @@ func (serverOptions *ServerRunOptions) Run(stopCh <-chan struct{}) error {
serverOptions
.
Etcd
.
StorageConfig
.
ServerList
=
[]
string
{
"http://127.0.0.1:2379"
}
// set defaults
if
err
:=
serverOptions
.
GenericServerRunOptions
.
DefaultExternalHost
(
);
err
!=
nil
{
if
err
:=
serverOptions
.
CloudProvider
.
DefaultExternalHost
(
serverOptions
.
GenericServerRunOptions
);
err
!=
nil
{
return
err
}
if
err
:=
serverOptions
.
SecureServing
.
MaybeDefaultWithSelfSignedCerts
(
serverOptions
.
GenericServerRunOptions
.
AdvertiseAddress
.
String
());
err
!=
nil
{
...
...
federation/cmd/federation-apiserver/app/options/options.go
View file @
f96fa748
...
...
@@ -34,6 +34,7 @@ type ServerRunOptions struct {
InsecureServing
*
genericoptions
.
ServingOptions
Authentication
*
kubeoptions
.
BuiltInAuthenticationOptions
Authorization
*
kubeoptions
.
BuiltInAuthorizationOptions
CloudProvider
*
kubeoptions
.
CloudProviderOptions
EventTTL
time
.
Duration
}
...
...
@@ -47,6 +48,7 @@ func NewServerRunOptions() *ServerRunOptions {
InsecureServing
:
genericoptions
.
NewInsecureServingOptions
(),
Authentication
:
kubeoptions
.
NewBuiltInAuthenticationOptions
()
.
WithAll
(),
Authorization
:
kubeoptions
.
NewBuiltInAuthorizationOptions
(),
CloudProvider
:
kubeoptions
.
NewCloudProviderOptions
(),
EventTTL
:
1
*
time
.
Hour
,
}
...
...
@@ -62,6 +64,7 @@ func (s *ServerRunOptions) AddFlags(fs *pflag.FlagSet) {
s
.
InsecureServing
.
AddFlags
(
fs
)
s
.
Authentication
.
AddFlags
(
fs
)
s
.
Authorization
.
AddFlags
(
fs
)
s
.
CloudProvider
.
AddFlags
(
fs
)
fs
.
DurationVar
(
&
s
.
EventTTL
,
"event-ttl"
,
s
.
EventTTL
,
"Amount of time to retain events. Default is 1h."
)
...
...
federation/cmd/federation-apiserver/app/server.go
View file @
f96fa748
...
...
@@ -73,7 +73,7 @@ func Run(s *options.ServerRunOptions) error {
if
err
:=
s
.
SecureServing
.
MaybeDefaultWithSelfSignedCerts
(
s
.
GenericServerRunOptions
.
AdvertiseAddress
.
String
());
err
!=
nil
{
return
fmt
.
Errorf
(
"error creating self-signed certificates: %v"
,
err
)
}
if
err
:=
s
.
GenericServerRunOptions
.
DefaultExternalHost
(
);
err
!=
nil
{
if
err
:=
s
.
CloudProvider
.
DefaultExternalHost
(
s
.
GenericServerRunOptions
);
err
!=
nil
{
return
fmt
.
Errorf
(
"error setting the external host value: %v"
,
err
)
}
...
...
pkg/genericapiserver/options/BUILD
View file @
f96fa748
...
...
@@ -21,13 +21,11 @@ go_library(
deps = [
"//pkg/admission:go_default_library",
"//pkg/api:go_default_library",
"//pkg/api/v1:go_default_library",
"//pkg/apimachinery/registered:go_default_library",
"//pkg/client/clientset_generated/clientset/typed/authentication/v1beta1:go_default_library",
"//pkg/client/clientset_generated/clientset/typed/authorization/v1beta1:go_default_library",
"//pkg/client/restclient:go_default_library",
"//pkg/client/unversioned/clientcmd:go_default_library",
"//pkg/cloudprovider:go_default_library",
"//pkg/genericapiserver/authenticator:go_default_library",
"//pkg/genericapiserver/authorizer:go_default_library",
"//pkg/runtime/schema:go_default_library",
...
...
pkg/genericapiserver/options/server_run_options.go
View file @
f96fa748
...
...
@@ -19,14 +19,11 @@ package options
import
(
"fmt"
"net"
"os"
"strings"
"k8s.io/kubernetes/pkg/admission"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/apimachinery/registered"
"k8s.io/kubernetes/pkg/cloudprovider"
"k8s.io/kubernetes/pkg/runtime/schema"
"k8s.io/kubernetes/pkg/util/config"
...
...
@@ -39,8 +36,6 @@ type ServerRunOptions struct {
AdmissionControlConfigFile
string
AdvertiseAddress
net
.
IP
CloudConfigFile
string
CloudProvider
string
CorsAllowedOriginList
[]
string
DefaultStorageMediaType
string
DeleteCollectionWorkers
int
...
...
@@ -109,44 +104,6 @@ func (s *ServerRunOptions) DefaultAdvertiseAddress(secure *SecureServingOptions,
return
nil
}
func
(
options
*
ServerRunOptions
)
DefaultExternalHost
()
error
{
if
len
(
options
.
ExternalHost
)
!=
0
{
return
nil
}
// TODO: extend for other providers
if
options
.
CloudProvider
==
"gce"
||
options
.
CloudProvider
==
"aws"
{
cloud
,
err
:=
cloudprovider
.
InitCloudProvider
(
options
.
CloudProvider
,
options
.
CloudConfigFile
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"%q cloud provider could not be initialized: %v"
,
options
.
CloudProvider
,
err
)
}
instances
,
supported
:=
cloud
.
Instances
()
if
!
supported
{
return
fmt
.
Errorf
(
"%q cloud provider has no instances"
,
options
.
CloudProvider
)
}
hostname
,
err
:=
os
.
Hostname
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to get hostname: %v"
,
err
)
}
nodeName
,
err
:=
instances
.
CurrentNodeName
(
hostname
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to get NodeName from %q cloud provider: %v"
,
options
.
CloudProvider
,
err
)
}
addrs
,
err
:=
instances
.
NodeAddresses
(
nodeName
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to get external host address from %q cloud provider: %v"
,
options
.
CloudProvider
,
err
)
}
else
{
for
_
,
addr
:=
range
addrs
{
if
addr
.
Type
==
v1
.
NodeExternalIP
{
options
.
ExternalHost
=
addr
.
Address
}
}
}
}
return
nil
}
// StorageGroupsToEncodingVersion returns a map from group name to group version,
// computed from s.StorageVersions flag.
func
(
s
*
ServerRunOptions
)
StorageGroupsToEncodingVersion
()
(
map
[
string
]
schema
.
GroupVersion
,
error
)
{
...
...
@@ -211,12 +168,6 @@ func (s *ServerRunOptions) AddUniversalFlags(fs *pflag.FlagSet) {
"will be used. If --bind-address is unspecified, the host's default interface will "
+
"be used."
)
fs
.
StringVar
(
&
s
.
CloudProvider
,
"cloud-provider"
,
s
.
CloudProvider
,
"The provider for cloud services. Empty string for no provider."
)
fs
.
StringVar
(
&
s
.
CloudConfigFile
,
"cloud-config"
,
s
.
CloudConfigFile
,
"The path to the cloud provider configuration file. Empty string for no configuration file."
)
fs
.
StringSliceVar
(
&
s
.
CorsAllowedOriginList
,
"cors-allowed-origins"
,
s
.
CorsAllowedOriginList
,
""
+
"List of allowed origins for CORS, comma separated. An allowed origin can be a regular "
+
"expression to support subdomain matching. If this list is empty CORS will not be enabled."
)
...
...
pkg/kubeapiserver/options/BUILD
View file @
f96fa748
...
...
@@ -12,9 +12,12 @@ go_library(
srcs = [
"authentication.go",
"authorization.go",
"cloudprovider.go",
],
tags = ["automanaged"],
deps = [
"//pkg/api/v1:go_default_library",
"//pkg/cloudprovider:go_default_library",
"//pkg/controller/informers:go_default_library",
"//pkg/genericapiserver:go_default_library",
"//pkg/genericapiserver/options:go_default_library",
...
...
pkg/kubeapiserver/options/cloudprovider.go
0 → 100644
View file @
f96fa748
/*
Copyright 2017 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.
*/
package
options
import
(
"fmt"
"os"
"github.com/spf13/pflag"
"k8s.io/kubernetes/pkg/api/v1"
"k8s.io/kubernetes/pkg/cloudprovider"
genericoptions
"k8s.io/kubernetes/pkg/genericapiserver/options"
)
type
CloudProviderOptions
struct
{
CloudConfigFile
string
CloudProvider
string
}
func
NewCloudProviderOptions
()
*
CloudProviderOptions
{
return
&
CloudProviderOptions
{}
}
func
(
s
*
CloudProviderOptions
)
Validate
()
[]
error
{
allErrors
:=
[]
error
{}
return
allErrors
}
func
(
s
*
CloudProviderOptions
)
AddFlags
(
fs
*
pflag
.
FlagSet
)
{
fs
.
StringVar
(
&
s
.
CloudProvider
,
"cloud-provider"
,
s
.
CloudProvider
,
"The provider for cloud services. Empty string for no provider."
)
fs
.
StringVar
(
&
s
.
CloudConfigFile
,
"cloud-config"
,
s
.
CloudConfigFile
,
"The path to the cloud provider configuration file. Empty string for no configuration file."
)
}
func
(
s
*
CloudProviderOptions
)
DefaultExternalHost
(
genericoptions
*
genericoptions
.
ServerRunOptions
)
error
{
if
len
(
genericoptions
.
ExternalHost
)
!=
0
{
return
nil
}
// TODO: extend for other providers
if
s
.
CloudProvider
==
"gce"
||
s
.
CloudProvider
==
"aws"
{
cloud
,
err
:=
cloudprovider
.
InitCloudProvider
(
s
.
CloudProvider
,
s
.
CloudConfigFile
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"%q cloud provider could not be initialized: %v"
,
s
.
CloudProvider
,
err
)
}
instances
,
supported
:=
cloud
.
Instances
()
if
!
supported
{
return
fmt
.
Errorf
(
"%q cloud provider has no instances"
,
s
.
CloudProvider
)
}
hostname
,
err
:=
os
.
Hostname
()
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to get hostname: %v"
,
err
)
}
nodeName
,
err
:=
instances
.
CurrentNodeName
(
hostname
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to get NodeName from %q cloud provider: %v"
,
s
.
CloudProvider
,
err
)
}
addrs
,
err
:=
instances
.
NodeAddresses
(
nodeName
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to get external host address from %q cloud provider: %v"
,
s
.
CloudProvider
,
err
)
}
else
{
for
_
,
addr
:=
range
addrs
{
if
addr
.
Type
==
v1
.
NodeExternalIP
{
genericoptions
.
ExternalHost
=
addr
.
Address
}
}
}
}
return
nil
}
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