mirror of
https://github.com/rancher/norman.git
synced 2025-09-24 12:38:49 +00:00
Update vendor
This commit is contained in:
56
vendor/k8s.io/kubernetes/pkg/controller/clusterroleaggregation/BUILD
generated
vendored
Normal file
56
vendor/k8s.io/kubernetes/pkg/controller/clusterroleaggregation/BUILD
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["clusterroleaggregation_controller.go"],
|
||||
importpath = "k8s.io/kubernetes/pkg/controller/clusterroleaggregation",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//pkg/controller:go_default_library",
|
||||
"//staging/src/k8s.io/api/rbac/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/api/equality:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/informers/rbac/v1:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/kubernetes/typed/rbac/v1:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/listers/rbac/v1:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/tools/cache:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/util/workqueue:go_default_library",
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["clusterroleaggregation_controller_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//pkg/controller:go_default_library",
|
||||
"//staging/src/k8s.io/api/rbac/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/api/equality:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/diff:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/kubernetes/fake:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/listers/rbac/v1:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/testing:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/tools/cache:go_default_library",
|
||||
],
|
||||
)
|
213
vendor/k8s.io/kubernetes/pkg/controller/clusterroleaggregation/clusterroleaggregation_controller.go
generated
vendored
Normal file
213
vendor/k8s.io/kubernetes/pkg/controller/clusterroleaggregation/clusterroleaggregation_controller.go
generated
vendored
Normal file
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
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 clusterroleaggregation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
rbacv1 "k8s.io/api/rbac/v1"
|
||||
"k8s.io/apimachinery/pkg/api/equality"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
rbacinformers "k8s.io/client-go/informers/rbac/v1"
|
||||
rbacclient "k8s.io/client-go/kubernetes/typed/rbac/v1"
|
||||
rbaclisters "k8s.io/client-go/listers/rbac/v1"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
"k8s.io/client-go/util/workqueue"
|
||||
"k8s.io/kubernetes/pkg/controller"
|
||||
)
|
||||
|
||||
// ClusterRoleAggregationController is a controller to combine cluster roles
|
||||
type ClusterRoleAggregationController struct {
|
||||
clusterRoleClient rbacclient.ClusterRolesGetter
|
||||
clusterRoleLister rbaclisters.ClusterRoleLister
|
||||
clusterRolesSynced cache.InformerSynced
|
||||
|
||||
syncHandler func(key string) error
|
||||
queue workqueue.RateLimitingInterface
|
||||
}
|
||||
|
||||
// NewClusterRoleAggregation creates a new controller
|
||||
func NewClusterRoleAggregation(clusterRoleInformer rbacinformers.ClusterRoleInformer, clusterRoleClient rbacclient.ClusterRolesGetter) *ClusterRoleAggregationController {
|
||||
c := &ClusterRoleAggregationController{
|
||||
clusterRoleClient: clusterRoleClient,
|
||||
clusterRoleLister: clusterRoleInformer.Lister(),
|
||||
clusterRolesSynced: clusterRoleInformer.Informer().HasSynced,
|
||||
|
||||
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "ClusterRoleAggregator"),
|
||||
}
|
||||
c.syncHandler = c.syncClusterRole
|
||||
|
||||
clusterRoleInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
|
||||
AddFunc: func(obj interface{}) {
|
||||
c.enqueue()
|
||||
},
|
||||
UpdateFunc: func(old, cur interface{}) {
|
||||
c.enqueue()
|
||||
},
|
||||
DeleteFunc: func(uncast interface{}) {
|
||||
c.enqueue()
|
||||
},
|
||||
})
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *ClusterRoleAggregationController) syncClusterRole(key string) error {
|
||||
_, name, err := cache.SplitMetaNamespaceKey(key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sharedClusterRole, err := c.clusterRoleLister.Get(name)
|
||||
if errors.IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if sharedClusterRole.AggregationRule == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
newPolicyRules := []rbacv1.PolicyRule{}
|
||||
for i := range sharedClusterRole.AggregationRule.ClusterRoleSelectors {
|
||||
selector := sharedClusterRole.AggregationRule.ClusterRoleSelectors[i]
|
||||
runtimeLabelSelector, err := metav1.LabelSelectorAsSelector(&selector)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
clusterRoles, err := c.clusterRoleLister.List(runtimeLabelSelector)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sort.Sort(byName(clusterRoles))
|
||||
|
||||
for i := range clusterRoles {
|
||||
if clusterRoles[i].Name == sharedClusterRole.Name {
|
||||
continue
|
||||
}
|
||||
|
||||
for j := range clusterRoles[i].Rules {
|
||||
currRule := clusterRoles[i].Rules[j]
|
||||
if !ruleExists(newPolicyRules, currRule) {
|
||||
newPolicyRules = append(newPolicyRules, currRule)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if equality.Semantic.DeepEqual(newPolicyRules, sharedClusterRole.Rules) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// we need to update
|
||||
clusterRole := sharedClusterRole.DeepCopy()
|
||||
clusterRole.Rules = nil
|
||||
for _, rule := range newPolicyRules {
|
||||
clusterRole.Rules = append(clusterRole.Rules, *rule.DeepCopy())
|
||||
}
|
||||
_, err = c.clusterRoleClient.ClusterRoles().Update(clusterRole)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func ruleExists(haystack []rbacv1.PolicyRule, needle rbacv1.PolicyRule) bool {
|
||||
for _, curr := range haystack {
|
||||
if equality.Semantic.DeepEqual(curr, needle) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Run starts the controller and blocks until stopCh is closed.
|
||||
func (c *ClusterRoleAggregationController) Run(workers int, stopCh <-chan struct{}) {
|
||||
defer utilruntime.HandleCrash()
|
||||
defer c.queue.ShutDown()
|
||||
|
||||
glog.Infof("Starting ClusterRoleAggregator")
|
||||
defer glog.Infof("Shutting down ClusterRoleAggregator")
|
||||
|
||||
if !controller.WaitForCacheSync("ClusterRoleAggregator", stopCh, c.clusterRolesSynced) {
|
||||
return
|
||||
}
|
||||
|
||||
for i := 0; i < workers; i++ {
|
||||
go wait.Until(c.runWorker, time.Second, stopCh)
|
||||
}
|
||||
|
||||
<-stopCh
|
||||
}
|
||||
|
||||
func (c *ClusterRoleAggregationController) runWorker() {
|
||||
for c.processNextWorkItem() {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ClusterRoleAggregationController) processNextWorkItem() bool {
|
||||
dsKey, quit := c.queue.Get()
|
||||
if quit {
|
||||
return false
|
||||
}
|
||||
defer c.queue.Done(dsKey)
|
||||
|
||||
err := c.syncHandler(dsKey.(string))
|
||||
if err == nil {
|
||||
c.queue.Forget(dsKey)
|
||||
return true
|
||||
}
|
||||
|
||||
utilruntime.HandleError(fmt.Errorf("%v failed with : %v", dsKey, err))
|
||||
c.queue.AddRateLimited(dsKey)
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *ClusterRoleAggregationController) enqueue() {
|
||||
// this is unusual, but since the set of all clusterroles is small and we don't know the dependency
|
||||
// graph, just queue up every thing each time. This allows errors to be selectively retried if there
|
||||
// is a problem updating a single role
|
||||
allClusterRoles, err := c.clusterRoleLister.List(labels.Everything())
|
||||
if err != nil {
|
||||
utilruntime.HandleError(fmt.Errorf("Couldn't list all objects %v", err))
|
||||
return
|
||||
}
|
||||
for _, clusterRole := range allClusterRoles {
|
||||
// only queue ones that we may need to aggregate
|
||||
if clusterRole.AggregationRule == nil {
|
||||
continue
|
||||
}
|
||||
key, err := controller.KeyFunc(clusterRole)
|
||||
if err != nil {
|
||||
utilruntime.HandleError(fmt.Errorf("Couldn't get key for object %#v: %v", clusterRole, err))
|
||||
return
|
||||
}
|
||||
c.queue.Add(key)
|
||||
}
|
||||
}
|
||||
|
||||
type byName []*rbacv1.ClusterRole
|
||||
|
||||
func (a byName) Len() int { return len(a) }
|
||||
func (a byName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a byName) Less(i, j int) bool { return a[i].Name < a[j].Name }
|
63
vendor/k8s.io/kubernetes/pkg/controller/replication/BUILD
generated
vendored
Normal file
63
vendor/k8s.io/kubernetes/pkg/controller/replication/BUILD
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
"go_test",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"conversion.go",
|
||||
"doc.go",
|
||||
"replication_controller.go",
|
||||
"replication_controller_utils.go",
|
||||
],
|
||||
importpath = "k8s.io/kubernetes/pkg/controller/replication",
|
||||
deps = [
|
||||
"//pkg/apis/apps/v1:go_default_library",
|
||||
"//pkg/apis/core/v1:go_default_library",
|
||||
"//pkg/apis/extensions:go_default_library",
|
||||
"//pkg/controller:go_default_library",
|
||||
"//pkg/controller/replicaset:go_default_library",
|
||||
"//staging/src/k8s.io/api/apps/v1:go_default_library",
|
||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/watch:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/informers/core/v1:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/kubernetes/scheme:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/kubernetes/typed/apps/v1:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/kubernetes/typed/core/v1:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/listers/apps/v1:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/listers/core/v1:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/tools/cache:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/tools/record:go_default_library",
|
||||
"//vendor/github.com/golang/glog:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
go_test(
|
||||
name = "go_default_test",
|
||||
srcs = ["replication_controller_utils_test.go"],
|
||||
embed = [":go_default_library"],
|
||||
deps = ["//staging/src/k8s.io/api/core/v1:go_default_library"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
11
vendor/k8s.io/kubernetes/pkg/controller/replication/OWNERS
generated
vendored
Executable file
11
vendor/k8s.io/kubernetes/pkg/controller/replication/OWNERS
generated
vendored
Executable file
@@ -0,0 +1,11 @@
|
||||
approvers:
|
||||
- caesarxuchao
|
||||
- lavalamp
|
||||
- enisoc
|
||||
reviewers:
|
||||
- caesarxuchao
|
||||
- lavalamp
|
||||
- tnozicka
|
||||
- enisoc
|
||||
labels:
|
||||
- sig/apps
|
332
vendor/k8s.io/kubernetes/pkg/controller/replication/conversion.go
generated
vendored
Normal file
332
vendor/k8s.io/kubernetes/pkg/controller/replication/conversion.go
generated
vendored
Normal file
@@ -0,0 +1,332 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
// This file contains adapters that convert between RC and RS,
|
||||
// as if ReplicationController were an older API version of ReplicaSet.
|
||||
// It allows ReplicaSetController to directly replace the old ReplicationManager,
|
||||
// which was previously a manually-maintained copy-paste of RSC.
|
||||
|
||||
package replication
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
apps "k8s.io/api/apps/v1"
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
coreinformers "k8s.io/client-go/informers/core/v1"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
appsv1client "k8s.io/client-go/kubernetes/typed/apps/v1"
|
||||
v1client "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
appslisters "k8s.io/client-go/listers/apps/v1"
|
||||
v1listers "k8s.io/client-go/listers/core/v1"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
appsconversion "k8s.io/kubernetes/pkg/apis/apps/v1"
|
||||
apiv1 "k8s.io/kubernetes/pkg/apis/core/v1"
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
"k8s.io/kubernetes/pkg/controller"
|
||||
)
|
||||
|
||||
// informerAdapter implements ReplicaSetInformer by wrapping ReplicationControllerInformer
|
||||
// and converting objects.
|
||||
type informerAdapter struct {
|
||||
rcInformer coreinformers.ReplicationControllerInformer
|
||||
}
|
||||
|
||||
func (i informerAdapter) Informer() cache.SharedIndexInformer {
|
||||
return conversionInformer{i.rcInformer.Informer()}
|
||||
}
|
||||
|
||||
func (i informerAdapter) Lister() appslisters.ReplicaSetLister {
|
||||
return conversionLister{i.rcInformer.Lister()}
|
||||
}
|
||||
|
||||
type conversionInformer struct {
|
||||
cache.SharedIndexInformer
|
||||
}
|
||||
|
||||
func (i conversionInformer) AddEventHandler(handler cache.ResourceEventHandler) {
|
||||
i.SharedIndexInformer.AddEventHandler(conversionEventHandler{handler})
|
||||
}
|
||||
|
||||
func (i conversionInformer) AddEventHandlerWithResyncPeriod(handler cache.ResourceEventHandler, resyncPeriod time.Duration) {
|
||||
i.SharedIndexInformer.AddEventHandlerWithResyncPeriod(conversionEventHandler{handler}, resyncPeriod)
|
||||
}
|
||||
|
||||
type conversionLister struct {
|
||||
rcLister v1listers.ReplicationControllerLister
|
||||
}
|
||||
|
||||
func (l conversionLister) List(selector labels.Selector) ([]*apps.ReplicaSet, error) {
|
||||
rcList, err := l.rcLister.List(selector)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return convertSlice(rcList)
|
||||
}
|
||||
|
||||
func (l conversionLister) ReplicaSets(namespace string) appslisters.ReplicaSetNamespaceLister {
|
||||
return conversionNamespaceLister{l.rcLister.ReplicationControllers(namespace)}
|
||||
}
|
||||
|
||||
func (l conversionLister) GetPodReplicaSets(pod *v1.Pod) ([]*apps.ReplicaSet, error) {
|
||||
rcList, err := l.rcLister.GetPodControllers(pod)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return convertSlice(rcList)
|
||||
}
|
||||
|
||||
type conversionNamespaceLister struct {
|
||||
rcLister v1listers.ReplicationControllerNamespaceLister
|
||||
}
|
||||
|
||||
func (l conversionNamespaceLister) List(selector labels.Selector) ([]*apps.ReplicaSet, error) {
|
||||
rcList, err := l.rcLister.List(selector)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return convertSlice(rcList)
|
||||
}
|
||||
|
||||
func (l conversionNamespaceLister) Get(name string) (*apps.ReplicaSet, error) {
|
||||
rc, err := l.rcLister.Get(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return convertRCtoRS(rc, nil)
|
||||
}
|
||||
|
||||
type conversionEventHandler struct {
|
||||
handler cache.ResourceEventHandler
|
||||
}
|
||||
|
||||
func (h conversionEventHandler) OnAdd(obj interface{}) {
|
||||
rs, err := convertRCtoRS(obj.(*v1.ReplicationController), nil)
|
||||
if err != nil {
|
||||
utilruntime.HandleError(fmt.Errorf("dropping RC OnAdd event: can't convert object %#v to RS: %v", obj, err))
|
||||
return
|
||||
}
|
||||
h.handler.OnAdd(rs)
|
||||
}
|
||||
|
||||
func (h conversionEventHandler) OnUpdate(oldObj, newObj interface{}) {
|
||||
oldRS, err := convertRCtoRS(oldObj.(*v1.ReplicationController), nil)
|
||||
if err != nil {
|
||||
utilruntime.HandleError(fmt.Errorf("dropping RC OnUpdate event: can't convert old object %#v to RS: %v", oldObj, err))
|
||||
return
|
||||
}
|
||||
newRS, err := convertRCtoRS(newObj.(*v1.ReplicationController), nil)
|
||||
if err != nil {
|
||||
utilruntime.HandleError(fmt.Errorf("dropping RC OnUpdate event: can't convert new object %#v to RS: %v", newObj, err))
|
||||
return
|
||||
}
|
||||
h.handler.OnUpdate(oldRS, newRS)
|
||||
}
|
||||
|
||||
func (h conversionEventHandler) OnDelete(obj interface{}) {
|
||||
rc, ok := obj.(*v1.ReplicationController)
|
||||
if !ok {
|
||||
// Convert the Obj inside DeletedFinalStateUnknown.
|
||||
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
|
||||
if !ok {
|
||||
utilruntime.HandleError(fmt.Errorf("dropping RC OnDelete event: couldn't get object from tombstone %+v", obj))
|
||||
return
|
||||
}
|
||||
rc, ok = tombstone.Obj.(*v1.ReplicationController)
|
||||
if !ok {
|
||||
utilruntime.HandleError(fmt.Errorf("dropping RC OnDelete event: tombstone contained object that is not a RC %#v", obj))
|
||||
return
|
||||
}
|
||||
rs, err := convertRCtoRS(rc, nil)
|
||||
if err != nil {
|
||||
utilruntime.HandleError(fmt.Errorf("dropping RC OnDelete event: can't convert object %#v to RS: %v", obj, err))
|
||||
return
|
||||
}
|
||||
h.handler.OnDelete(cache.DeletedFinalStateUnknown{Key: tombstone.Key, Obj: rs})
|
||||
return
|
||||
}
|
||||
|
||||
// It's a regular RC object.
|
||||
rs, err := convertRCtoRS(rc, nil)
|
||||
if err != nil {
|
||||
utilruntime.HandleError(fmt.Errorf("dropping RC OnDelete event: can't convert object %#v to RS: %v", obj, err))
|
||||
return
|
||||
}
|
||||
h.handler.OnDelete(rs)
|
||||
}
|
||||
|
||||
type clientsetAdapter struct {
|
||||
clientset.Interface
|
||||
}
|
||||
|
||||
func (c clientsetAdapter) AppsV1() appsv1client.AppsV1Interface {
|
||||
return conversionAppsV1Client{c.Interface, c.Interface.AppsV1()}
|
||||
}
|
||||
|
||||
func (c clientsetAdapter) Apps() appsv1client.AppsV1Interface {
|
||||
return conversionAppsV1Client{c.Interface, c.Interface.AppsV1()}
|
||||
}
|
||||
|
||||
type conversionAppsV1Client struct {
|
||||
clientset clientset.Interface
|
||||
appsv1client.AppsV1Interface
|
||||
}
|
||||
|
||||
func (c conversionAppsV1Client) ReplicaSets(namespace string) appsv1client.ReplicaSetInterface {
|
||||
return conversionClient{c.clientset.CoreV1().ReplicationControllers(namespace)}
|
||||
}
|
||||
|
||||
type conversionClient struct {
|
||||
v1client.ReplicationControllerInterface
|
||||
}
|
||||
|
||||
func (c conversionClient) Create(rs *apps.ReplicaSet) (*apps.ReplicaSet, error) {
|
||||
return convertCall(c.ReplicationControllerInterface.Create, rs)
|
||||
}
|
||||
|
||||
func (c conversionClient) Update(rs *apps.ReplicaSet) (*apps.ReplicaSet, error) {
|
||||
return convertCall(c.ReplicationControllerInterface.Update, rs)
|
||||
}
|
||||
|
||||
func (c conversionClient) UpdateStatus(rs *apps.ReplicaSet) (*apps.ReplicaSet, error) {
|
||||
return convertCall(c.ReplicationControllerInterface.UpdateStatus, rs)
|
||||
}
|
||||
|
||||
func (c conversionClient) Get(name string, options metav1.GetOptions) (*apps.ReplicaSet, error) {
|
||||
rc, err := c.ReplicationControllerInterface.Get(name, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return convertRCtoRS(rc, nil)
|
||||
}
|
||||
|
||||
func (c conversionClient) List(opts metav1.ListOptions) (*apps.ReplicaSetList, error) {
|
||||
rcList, err := c.ReplicationControllerInterface.List(opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return convertList(rcList)
|
||||
}
|
||||
|
||||
func (c conversionClient) Watch(opts metav1.ListOptions) (watch.Interface, error) {
|
||||
// This is not used by RSC because we wrap the shared informer instead.
|
||||
return nil, errors.New("Watch() is not implemented for conversionClient")
|
||||
}
|
||||
|
||||
func (c conversionClient) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *apps.ReplicaSet, err error) {
|
||||
// This is not used by RSC.
|
||||
return nil, errors.New("Patch() is not implemented for conversionClient")
|
||||
}
|
||||
|
||||
func convertSlice(rcList []*v1.ReplicationController) ([]*apps.ReplicaSet, error) {
|
||||
rsList := make([]*apps.ReplicaSet, 0, len(rcList))
|
||||
for _, rc := range rcList {
|
||||
rs, err := convertRCtoRS(rc, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rsList = append(rsList, rs)
|
||||
}
|
||||
return rsList, nil
|
||||
}
|
||||
|
||||
func convertList(rcList *v1.ReplicationControllerList) (*apps.ReplicaSetList, error) {
|
||||
rsList := &apps.ReplicaSetList{Items: make([]apps.ReplicaSet, len(rcList.Items))}
|
||||
for i := range rcList.Items {
|
||||
rc := &rcList.Items[i]
|
||||
_, err := convertRCtoRS(rc, &rsList.Items[i])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return rsList, nil
|
||||
}
|
||||
|
||||
func convertCall(fn func(*v1.ReplicationController) (*v1.ReplicationController, error), rs *apps.ReplicaSet) (*apps.ReplicaSet, error) {
|
||||
rc, err := convertRStoRC(rs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result, err := fn(rc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return convertRCtoRS(result, nil)
|
||||
}
|
||||
|
||||
func convertRCtoRS(rc *v1.ReplicationController, out *apps.ReplicaSet) (*apps.ReplicaSet, error) {
|
||||
var rsInternal extensions.ReplicaSet
|
||||
if err := apiv1.Convert_v1_ReplicationController_To_extensions_ReplicaSet(rc, &rsInternal, nil); err != nil {
|
||||
return nil, fmt.Errorf("can't convert ReplicationController %v/%v to ReplicaSet: %v", rc.Namespace, rc.Name, err)
|
||||
}
|
||||
if out == nil {
|
||||
out = new(apps.ReplicaSet)
|
||||
}
|
||||
if err := appsconversion.Convert_extensions_ReplicaSet_To_v1_ReplicaSet(&rsInternal, out, nil); err != nil {
|
||||
return nil, fmt.Errorf("can't convert ReplicaSet (converted from ReplicationController %v/%v) from internal to extensions/v1beta1: %v", rc.Namespace, rc.Name, err)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func convertRStoRC(rs *apps.ReplicaSet) (*v1.ReplicationController, error) {
|
||||
var rsInternal extensions.ReplicaSet
|
||||
if err := appsconversion.Convert_v1_ReplicaSet_To_extensions_ReplicaSet(rs, &rsInternal, nil); err != nil {
|
||||
return nil, fmt.Errorf("can't convert ReplicaSet (converting to ReplicationController %v/%v) from extensions/v1beta1 to internal: %v", rs.Namespace, rs.Name, err)
|
||||
}
|
||||
var rc v1.ReplicationController
|
||||
if err := apiv1.Convert_extensions_ReplicaSet_To_v1_ReplicationController(&rsInternal, &rc, nil); err != nil {
|
||||
return nil, fmt.Errorf("can't convert ReplicaSet to ReplicationController %v/%v: %v", rs.Namespace, rs.Name, err)
|
||||
}
|
||||
return &rc, nil
|
||||
}
|
||||
|
||||
type podControlAdapter struct {
|
||||
controller.PodControlInterface
|
||||
}
|
||||
|
||||
func (pc podControlAdapter) CreatePods(namespace string, template *v1.PodTemplateSpec, object runtime.Object) error {
|
||||
// This is not used by RSC.
|
||||
return errors.New("CreatePods() is not implemented for podControlAdapter")
|
||||
}
|
||||
|
||||
func (pc podControlAdapter) CreatePodsOnNode(nodeName, namespace string, template *v1.PodTemplateSpec, object runtime.Object, controllerRef *metav1.OwnerReference) error {
|
||||
// This is not used by RSC.
|
||||
return errors.New("CreatePodsOnNode() is not implemented for podControlAdapter")
|
||||
}
|
||||
|
||||
func (pc podControlAdapter) CreatePodsWithControllerRef(namespace string, template *v1.PodTemplateSpec, object runtime.Object, controllerRef *metav1.OwnerReference) error {
|
||||
rc, err := convertRStoRC(object.(*apps.ReplicaSet))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return pc.PodControlInterface.CreatePodsWithControllerRef(namespace, template, rc, controllerRef)
|
||||
}
|
||||
|
||||
func (pc podControlAdapter) DeletePod(namespace string, podID string, object runtime.Object) error {
|
||||
rc, err := convertRStoRC(object.(*apps.ReplicaSet))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return pc.PodControlInterface.DeletePod(namespace, podID, rc)
|
||||
}
|
19
vendor/k8s.io/kubernetes/pkg/controller/replication/doc.go
generated
vendored
Normal file
19
vendor/k8s.io/kubernetes/pkg/controller/replication/doc.go
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
Copyright 2014 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 replication contains logic for watching and synchronizing
|
||||
// replication controllers.
|
||||
package replication // import "k8s.io/kubernetes/pkg/controller/replication"
|
67
vendor/k8s.io/kubernetes/pkg/controller/replication/replication_controller.go
generated
vendored
Normal file
67
vendor/k8s.io/kubernetes/pkg/controller/replication/replication_controller.go
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
Copyright 2014 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.
|
||||
*/
|
||||
|
||||
// ### ATTENTION ###
|
||||
//
|
||||
// ReplicationManager is now just a wrapper around ReplicaSetController,
|
||||
// with a conversion layer that effectively treats ReplicationController
|
||||
// as if it were an older API version of ReplicaSet.
|
||||
//
|
||||
// However, RC and RS still have separate storage and separate instantiations
|
||||
// of the ReplicaSetController object.
|
||||
|
||||
package replication
|
||||
|
||||
import (
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/api/core/v1"
|
||||
coreinformers "k8s.io/client-go/informers/core/v1"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
|
||||
"k8s.io/client-go/tools/record"
|
||||
"k8s.io/kubernetes/pkg/controller"
|
||||
"k8s.io/kubernetes/pkg/controller/replicaset"
|
||||
)
|
||||
|
||||
const (
|
||||
BurstReplicas = replicaset.BurstReplicas
|
||||
)
|
||||
|
||||
// ReplicationManager is responsible for synchronizing ReplicationController objects stored
|
||||
// in the system with actual running pods.
|
||||
// It is actually just a wrapper around ReplicaSetController.
|
||||
type ReplicationManager struct {
|
||||
replicaset.ReplicaSetController
|
||||
}
|
||||
|
||||
// NewReplicationManager configures a replication manager with the specified event recorder
|
||||
func NewReplicationManager(podInformer coreinformers.PodInformer, rcInformer coreinformers.ReplicationControllerInformer, kubeClient clientset.Interface, burstReplicas int) *ReplicationManager {
|
||||
eventBroadcaster := record.NewBroadcaster()
|
||||
eventBroadcaster.StartLogging(glog.Infof)
|
||||
eventBroadcaster.StartRecordingToSink(&v1core.EventSinkImpl{Interface: kubeClient.CoreV1().Events("")})
|
||||
return &ReplicationManager{
|
||||
*replicaset.NewBaseController(informerAdapter{rcInformer}, podInformer, clientsetAdapter{kubeClient}, burstReplicas,
|
||||
v1.SchemeGroupVersion.WithKind("ReplicationController"),
|
||||
"replication_controller",
|
||||
"replicationmanager",
|
||||
podControlAdapter{controller.RealPodControl{
|
||||
KubeClient: kubeClient,
|
||||
Recorder: eventBroadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "replication-controller"}),
|
||||
}},
|
||||
),
|
||||
}
|
||||
}
|
73
vendor/k8s.io/kubernetes/pkg/controller/replication/replication_controller_utils.go
generated
vendored
Normal file
73
vendor/k8s.io/kubernetes/pkg/controller/replication/replication_controller_utils.go
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
Copyright 2015 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.
|
||||
*/
|
||||
|
||||
// If you make changes to this file, you should also make the corresponding change in ReplicaSet.
|
||||
|
||||
package replication
|
||||
|
||||
import (
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
// NewReplicationControllerCondition creates a new replication controller condition.
|
||||
func NewReplicationControllerCondition(condType v1.ReplicationControllerConditionType, status v1.ConditionStatus, reason, msg string) v1.ReplicationControllerCondition {
|
||||
return v1.ReplicationControllerCondition{
|
||||
Type: condType,
|
||||
Status: status,
|
||||
LastTransitionTime: metav1.Now(),
|
||||
Reason: reason,
|
||||
Message: msg,
|
||||
}
|
||||
}
|
||||
|
||||
// GetCondition returns a replication controller condition with the provided type if it exists.
|
||||
func GetCondition(status v1.ReplicationControllerStatus, condType v1.ReplicationControllerConditionType) *v1.ReplicationControllerCondition {
|
||||
for i := range status.Conditions {
|
||||
c := status.Conditions[i]
|
||||
if c.Type == condType {
|
||||
return &c
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetCondition adds/replaces the given condition in the replication controller status.
|
||||
func SetCondition(status *v1.ReplicationControllerStatus, condition v1.ReplicationControllerCondition) {
|
||||
currentCond := GetCondition(*status, condition.Type)
|
||||
if currentCond != nil && currentCond.Status == condition.Status && currentCond.Reason == condition.Reason {
|
||||
return
|
||||
}
|
||||
newConditions := filterOutCondition(status.Conditions, condition.Type)
|
||||
status.Conditions = append(newConditions, condition)
|
||||
}
|
||||
|
||||
// RemoveCondition removes the condition with the provided type from the replication controller status.
|
||||
func RemoveCondition(status *v1.ReplicationControllerStatus, condType v1.ReplicationControllerConditionType) {
|
||||
status.Conditions = filterOutCondition(status.Conditions, condType)
|
||||
}
|
||||
|
||||
// filterOutCondition returns a new slice of replication controller conditions without conditions with the provided type.
|
||||
func filterOutCondition(conditions []v1.ReplicationControllerCondition, condType v1.ReplicationControllerConditionType) []v1.ReplicationControllerCondition {
|
||||
var newConditions []v1.ReplicationControllerCondition
|
||||
for _, c := range conditions {
|
||||
if c.Type == condType {
|
||||
continue
|
||||
}
|
||||
newConditions = append(newConditions, c)
|
||||
}
|
||||
return newConditions
|
||||
}
|
Reference in New Issue
Block a user