mirror of https://github.com/kubernetes/kops.git
Merge pull request #2766 from justinsb/kops_server
Initial work on kops-server
This commit is contained in:
commit
5b7c1cfe2d
|
@ -34,6 +34,7 @@ k8s.io/kops/pkg/apis/nodeup
|
||||||
k8s.io/kops/pkg/apiserver
|
k8s.io/kops/pkg/apiserver
|
||||||
k8s.io/kops/pkg/apiserver/cmd/server
|
k8s.io/kops/pkg/apiserver/cmd/server
|
||||||
k8s.io/kops/pkg/apiserver/registry/cluster
|
k8s.io/kops/pkg/apiserver/registry/cluster
|
||||||
|
k8s.io/kops/pkg/apiserver/registry/instancegroup
|
||||||
k8s.io/kops/pkg/assets
|
k8s.io/kops/pkg/assets
|
||||||
k8s.io/kops/pkg/client/clientset_generated/clientset
|
k8s.io/kops/pkg/client/clientset_generated/clientset
|
||||||
k8s.io/kops/pkg/client/clientset_generated/clientset/fake
|
k8s.io/kops/pkg/client/clientset_generated/clientset/fake
|
||||||
|
|
|
@ -43,7 +43,8 @@ func Install(groupFactoryRegistry announced.APIGroupFactoryRegistry, registry *r
|
||||||
v1alpha2.SchemeGroupVersion.Version,
|
v1alpha2.SchemeGroupVersion.Version,
|
||||||
v1alpha1.SchemeGroupVersion.Version,
|
v1alpha1.SchemeGroupVersion.Version,
|
||||||
},
|
},
|
||||||
RootScopedKinds: sets.NewString("Cluster"),
|
// RootScopedKinds are resources that are not namespaced.
|
||||||
|
RootScopedKinds: sets.NewString(),
|
||||||
ImportPrefix: "k8s.io/kops/pkg/apis/kops",
|
ImportPrefix: "k8s.io/kops/pkg/apis/kops",
|
||||||
AddInternalObjectsToScheme: kops.AddToScheme,
|
AddInternalObjectsToScheme: kops.AddToScheme,
|
||||||
},
|
},
|
||||||
|
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||||
package apiserver
|
package apiserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"k8s.io/apimachinery/pkg/version"
|
||||||
"k8s.io/apiserver/pkg/registry/generic"
|
"k8s.io/apiserver/pkg/registry/generic"
|
||||||
"k8s.io/apiserver/pkg/registry/rest"
|
"k8s.io/apiserver/pkg/registry/rest"
|
||||||
"k8s.io/apiserver/pkg/server"
|
"k8s.io/apiserver/pkg/server"
|
||||||
|
@ -26,8 +27,7 @@ import (
|
||||||
_ "k8s.io/kops/pkg/apis/kops/install"
|
_ "k8s.io/kops/pkg/apis/kops/install"
|
||||||
"k8s.io/kops/pkg/apis/kops/v1alpha2"
|
"k8s.io/kops/pkg/apis/kops/v1alpha2"
|
||||||
registrycluster "k8s.io/kops/pkg/apiserver/registry/cluster"
|
registrycluster "k8s.io/kops/pkg/apiserver/registry/cluster"
|
||||||
//registryinstancegroup "k8s.io/kops/pkg/apiserver/registry/instancegroup"
|
registryinstancegroup "k8s.io/kops/pkg/apiserver/registry/instancegroup"
|
||||||
"k8s.io/kubernetes/pkg/version"
|
|
||||||
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
|
@ -69,8 +69,10 @@ type completedConfig struct {
|
||||||
func (c *Config) Complete() completedConfig {
|
func (c *Config) Complete() completedConfig {
|
||||||
c.GenericConfig.Complete()
|
c.GenericConfig.Complete()
|
||||||
|
|
||||||
version := version.Get()
|
c.GenericConfig.Version = &version.Info{
|
||||||
c.GenericConfig.Version = &version
|
Major: "1",
|
||||||
|
Minor: "0",
|
||||||
|
}
|
||||||
|
|
||||||
return completedConfig{c}
|
return completedConfig{c}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +98,8 @@ func (c completedConfig) New() (*APIDiscoveryServer, error) {
|
||||||
apiGroupInfo.GroupMeta.GroupVersion = v1alpha2.SchemeGroupVersion
|
apiGroupInfo.GroupMeta.GroupVersion = v1alpha2.SchemeGroupVersion
|
||||||
v1alpha2storage := map[string]rest.Storage{}
|
v1alpha2storage := map[string]rest.Storage{}
|
||||||
v1alpha2storage["clusters"] = registrycluster.NewREST(c.RESTOptionsGetter)
|
v1alpha2storage["clusters"] = registrycluster.NewREST(c.RESTOptionsGetter)
|
||||||
//v1alpha2storage["instancegroups"] = registryinstancegroup.NewREST(c.RESTOptionsGetter)
|
//v1alpha2storage["clusters/full"] = registrycluster.NewREST(c.RESTOptionsGetter)
|
||||||
|
v1alpha2storage["instancegroups"] = registryinstancegroup.NewREST(c.RESTOptionsGetter)
|
||||||
apiGroupInfo.VersionedResourcesStorageMap["v1alpha2"] = v1alpha2storage
|
apiGroupInfo.VersionedResourcesStorageMap["v1alpha2"] = v1alpha2storage
|
||||||
|
|
||||||
if err := s.GenericAPIServer.InstallAPIGroup(&apiGroupInfo); err != nil {
|
if err := s.GenericAPIServer.InstallAPIGroup(&apiGroupInfo); err != nil {
|
||||||
|
|
|
@ -105,7 +105,7 @@ func (o KopsServerOptions) RunKopsServer() error {
|
||||||
serverConfig := genericapiserver.NewConfig(kops.Codecs)
|
serverConfig := genericapiserver.NewConfig(kops.Codecs)
|
||||||
// 1.6: serverConfig := genericapiserver.NewConfig().WithSerializer(kops.Codecs)
|
// 1.6: serverConfig := genericapiserver.NewConfig().WithSerializer(kops.Codecs)
|
||||||
//if err := o.RecommendedOptions.ApplyTo(serverConfig); err != nil {
|
//if err := o.RecommendedOptions.ApplyTo(serverConfig); err != nil {
|
||||||
// return nil, err
|
// return nil, err
|
||||||
//}
|
//}
|
||||||
|
|
||||||
serverConfig.CorsAllowedOriginList = []string{".*"}
|
serverConfig.CorsAllowedOriginList = []string{".*"}
|
||||||
|
@ -139,7 +139,6 @@ func (o KopsServerOptions) RunKopsServer() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return server.GenericAPIServer.PrepareRun().Run(wait.NeverStop)
|
return server.GenericAPIServer.PrepareRun().Run(wait.NeverStop)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type restOptionsFactory struct {
|
type restOptionsFactory struct {
|
||||||
|
|
|
@ -39,7 +39,7 @@ type clusterStrategy struct {
|
||||||
var Strategy = clusterStrategy{kops.Scheme, names.SimpleNameGenerator}
|
var Strategy = clusterStrategy{kops.Scheme, names.SimpleNameGenerator}
|
||||||
|
|
||||||
func (clusterStrategy) NamespaceScoped() bool {
|
func (clusterStrategy) NamespaceScoped() bool {
|
||||||
return false
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (clusterStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object) {
|
func (clusterStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object) {
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
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 instancegroup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/apiserver/pkg/registry/generic"
|
||||||
|
genericregistry "k8s.io/apiserver/pkg/registry/generic/registry"
|
||||||
|
|
||||||
|
"k8s.io/kops/pkg/apis/kops"
|
||||||
|
)
|
||||||
|
|
||||||
|
// rest implements a RESTStorage for kops InstanceGroups against etcd
|
||||||
|
type REST struct {
|
||||||
|
*genericregistry.Store
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewREST returns a RESTStorage object that will work against kops InstanceGroups.
|
||||||
|
func NewREST(optsGetter generic.RESTOptionsGetter) *REST {
|
||||||
|
store := &genericregistry.Store{
|
||||||
|
Copier: kops.Scheme,
|
||||||
|
NewFunc: func() runtime.Object {
|
||||||
|
return &kops.InstanceGroup{}
|
||||||
|
},
|
||||||
|
NewListFunc: func() runtime.Object {
|
||||||
|
return &kops.InstanceGroupList{}
|
||||||
|
},
|
||||||
|
ObjectNameFunc: func(obj runtime.Object) (string, error) {
|
||||||
|
return obj.(*kops.InstanceGroup).Name, nil
|
||||||
|
},
|
||||||
|
PredicateFunc: MatchInstanceGroup,
|
||||||
|
QualifiedResource: kops.Resource("instancegroups"),
|
||||||
|
|
||||||
|
CreateStrategy: Strategy,
|
||||||
|
UpdateStrategy: Strategy,
|
||||||
|
DeleteStrategy: Strategy,
|
||||||
|
}
|
||||||
|
options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: GetAttrs}
|
||||||
|
if err := store.CompleteWithOptions(options); err != nil {
|
||||||
|
panic(err) // TODO: Propagate error up
|
||||||
|
}
|
||||||
|
return &REST{store}
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
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 instancegroup
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"k8s.io/apimachinery/pkg/fields"
|
||||||
|
"k8s.io/apimachinery/pkg/labels"
|
||||||
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
|
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||||
|
genericapirequest "k8s.io/apiserver/pkg/endpoints/request"
|
||||||
|
"k8s.io/apiserver/pkg/registry/generic"
|
||||||
|
"k8s.io/apiserver/pkg/storage"
|
||||||
|
"k8s.io/apiserver/pkg/storage/names"
|
||||||
|
|
||||||
|
"k8s.io/kops/pkg/apis/kops"
|
||||||
|
)
|
||||||
|
|
||||||
|
type instanceGroupStrategy struct {
|
||||||
|
runtime.ObjectTyper
|
||||||
|
names.NameGenerator
|
||||||
|
}
|
||||||
|
|
||||||
|
var Strategy = instanceGroupStrategy{kops.Scheme, names.SimpleNameGenerator}
|
||||||
|
|
||||||
|
func (instanceGroupStrategy) NamespaceScoped() bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (instanceGroupStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Object) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (instanceGroupStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runtime.Object) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (instanceGroupStrategy) Validate(ctx genericapirequest.Context, obj runtime.Object) field.ErrorList {
|
||||||
|
return field.ErrorList{}
|
||||||
|
// return validation.ValidateServiceInjection(obj.(*serviceinjection.ServiceInjection))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (instanceGroupStrategy) AllowCreateOnUpdate() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (instanceGroupStrategy) AllowUnconditionalUpdate() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (instanceGroupStrategy) Canonicalize(obj runtime.Object) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (instanceGroupStrategy) ValidateUpdate(ctx genericapirequest.Context, obj, old runtime.Object) field.ErrorList {
|
||||||
|
return field.ErrorList{}
|
||||||
|
// return validation.ValidateServiceInjectionUpdate(obj.(*serviceinjection.ServiceInjection), old.(*serviceinjection.ServiceInjection))
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, bool, error) {
|
||||||
|
instanceGroup, ok := obj.(*kops.InstanceGroup)
|
||||||
|
if !ok {
|
||||||
|
return nil, nil, false, fmt.Errorf("given object is not an InstanceGroup.")
|
||||||
|
}
|
||||||
|
return labels.Set(instanceGroup.Labels), InstanceGroupToSelectableFields(instanceGroup), instanceGroup.Initializers != nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MatchInstanceGroup is the filter used by the generic etcd backend to watch events
|
||||||
|
// from etcd to clients of the apiserver only interested in specific labels/fields.
|
||||||
|
func MatchInstanceGroup(label labels.Selector, field fields.Selector) storage.SelectionPredicate {
|
||||||
|
return storage.SelectionPredicate{
|
||||||
|
Label: label,
|
||||||
|
Field: field,
|
||||||
|
GetAttrs: GetAttrs,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// InstanceGroupToSelectableFields returns a field set that represents the object.
|
||||||
|
func InstanceGroupToSelectableFields(obj *kops.InstanceGroup) fields.Set {
|
||||||
|
return generic.ObjectMetaFieldsSet(&obj.ObjectMeta, true)
|
||||||
|
}
|
|
@ -35,7 +35,7 @@ import (
|
||||||
"k8s.io/kops/pkg/apis/kops"
|
"k8s.io/kops/pkg/apis/kops"
|
||||||
"k8s.io/kops/upup/pkg/fi"
|
"k8s.io/kops/upup/pkg/fi"
|
||||||
"k8s.io/kubernetes/federation/pkg/dnsprovider"
|
"k8s.io/kubernetes/federation/pkg/dnsprovider"
|
||||||
k8sroute53 "k8s.io/kubernetes/federation/pkg/dnsprovider/providers/aws/route53"
|
dnsproviderroute53 "k8s.io/kubernetes/federation/pkg/dnsprovider/providers/aws/route53"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -683,7 +683,7 @@ func ValidateZones(zones []string, cloud AWSCloud) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *awsCloudImplementation) DNS() (dnsprovider.Interface, error) {
|
func (c *awsCloudImplementation) DNS() (dnsprovider.Interface, error) {
|
||||||
provider, err := dnsprovider.GetDnsProvider(k8sroute53.ProviderName, nil)
|
provider, err := dnsprovider.GetDnsProvider(dnsproviderroute53.ProviderName, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Error building (k8s) DNS provider: %v", err)
|
return nil, fmt.Errorf("Error building (k8s) DNS provider: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue