add service mesh controller
add service mesh metrics remove unused circle yaml fix travis misconfiguration fix travis misconfiguration fix travis misconfiguration
This commit is contained in:
94
vendor/sigs.k8s.io/controller-runtime/pkg/controller/controller.go
generated
vendored
Normal file
94
vendor/sigs.k8s.io/controller-runtime/pkg/controller/controller.go
generated
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
Copyright 2018 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 controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/client-go/util/workqueue"
|
||||
"sigs.k8s.io/controller-runtime/pkg/handler"
|
||||
"sigs.k8s.io/controller-runtime/pkg/internal/controller"
|
||||
"sigs.k8s.io/controller-runtime/pkg/manager"
|
||||
"sigs.k8s.io/controller-runtime/pkg/predicate"
|
||||
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
||||
"sigs.k8s.io/controller-runtime/pkg/source"
|
||||
)
|
||||
|
||||
// Options are the arguments for creating a new Controller
|
||||
type Options struct {
|
||||
// MaxConcurrentReconciles is the maximum number of concurrent Reconciles which can be run. Defaults to 1.
|
||||
MaxConcurrentReconciles int
|
||||
|
||||
// Reconciler reconciles an object
|
||||
Reconciler reconcile.Reconciler
|
||||
}
|
||||
|
||||
// Controller implements a Kubernetes API. A Controller manages a work queue fed reconcile.Requests
|
||||
// from source.Sources. Work is performed through the reconcile.Reconciler for each enqueued item.
|
||||
// Work typically is reads and writes Kubernetes objects to make the system state match the state specified
|
||||
// in the object Spec.
|
||||
type Controller interface {
|
||||
// Reconciler is called to Reconciler an object by Namespace/Name
|
||||
reconcile.Reconciler
|
||||
|
||||
// Watch takes events provided by a Source and uses the EventHandler to enqueue reconcile.Requests in
|
||||
// response to the events.
|
||||
//
|
||||
// Watch may be provided one or more Predicates to filter events before they are given to the EventHandler.
|
||||
// Events will be passed to the EventHandler iff all provided Predicates evaluate to true.
|
||||
Watch(src source.Source, eventhandler handler.EventHandler, predicates ...predicate.Predicate) error
|
||||
|
||||
// Start starts the controller. Start blocks until stop is closed or a controller has an error starting.
|
||||
Start(stop <-chan struct{}) error
|
||||
}
|
||||
|
||||
// New returns a new Controller registered with the Manager. The Manager will ensure that shared Caches have
|
||||
// been synced before the Controller is Started.
|
||||
func New(name string, mgr manager.Manager, options Options) (Controller, error) {
|
||||
if options.Reconciler == nil {
|
||||
return nil, fmt.Errorf("must specify Reconciler")
|
||||
}
|
||||
|
||||
if len(name) == 0 {
|
||||
return nil, fmt.Errorf("must specify Name for Controller")
|
||||
}
|
||||
|
||||
if options.MaxConcurrentReconciles <= 0 {
|
||||
options.MaxConcurrentReconciles = 1
|
||||
}
|
||||
|
||||
// Inject dependencies into Reconciler
|
||||
if err := mgr.SetFields(options.Reconciler); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create controller with dependencies set
|
||||
c := &controller.Controller{
|
||||
Do: options.Reconciler,
|
||||
Cache: mgr.GetCache(),
|
||||
Config: mgr.GetConfig(),
|
||||
Scheme: mgr.GetScheme(),
|
||||
Client: mgr.GetClient(),
|
||||
Recorder: mgr.GetRecorder(name),
|
||||
Queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), name),
|
||||
MaxConcurrentReconciles: options.MaxConcurrentReconciles,
|
||||
Name: name,
|
||||
}
|
||||
|
||||
// Add the controller as a Manager components
|
||||
return c, mgr.Add(c)
|
||||
}
|
||||
178
vendor/sigs.k8s.io/controller-runtime/pkg/controller/controllerutil/controllerutil.go
generated
vendored
Normal file
178
vendor/sigs.k8s.io/controller-runtime/pkg/controller/controllerutil/controllerutil.go
generated
vendored
Normal file
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
Copyright 2018 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 controllerutil
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
|
||||
)
|
||||
|
||||
// AlreadyOwnedError is an error returned if the object you are trying to assign
|
||||
// a controller reference is already owned by another controller Object is the
|
||||
// subject and Owner is the reference for the current owner
|
||||
type AlreadyOwnedError struct {
|
||||
Object v1.Object
|
||||
Owner v1.OwnerReference
|
||||
}
|
||||
|
||||
func (e *AlreadyOwnedError) Error() string {
|
||||
return fmt.Sprintf("Object %s/%s is already owned by another %s controller %s", e.Object.GetNamespace(), e.Object.GetName(), e.Owner.Kind, e.Owner.Name)
|
||||
}
|
||||
|
||||
func newAlreadyOwnedError(Object v1.Object, Owner v1.OwnerReference) *AlreadyOwnedError {
|
||||
return &AlreadyOwnedError{
|
||||
Object: Object,
|
||||
Owner: Owner,
|
||||
}
|
||||
}
|
||||
|
||||
// SetControllerReference sets owner as a Controller OwnerReference on owned.
|
||||
// This is used for garbage collection of the owned object and for
|
||||
// reconciling the owner object on changes to owned (with a Watch + EnqueueRequestForOwner).
|
||||
// Since only one OwnerReference can be a controller, it returns an error if
|
||||
// there is another OwnerReference with Controller flag set.
|
||||
func SetControllerReference(owner, object v1.Object, scheme *runtime.Scheme) error {
|
||||
ro, ok := owner.(runtime.Object)
|
||||
if !ok {
|
||||
return fmt.Errorf("is not a %T a runtime.Object, cannot call SetControllerReference", owner)
|
||||
}
|
||||
|
||||
gvk, err := apiutil.GVKForObject(ro, scheme)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Create a new ref
|
||||
ref := *v1.NewControllerRef(owner, schema.GroupVersionKind{Group: gvk.Group, Version: gvk.Version, Kind: gvk.Kind})
|
||||
|
||||
existingRefs := object.GetOwnerReferences()
|
||||
fi := -1
|
||||
for i, r := range existingRefs {
|
||||
if referSameObject(ref, r) {
|
||||
fi = i
|
||||
} else if r.Controller != nil && *r.Controller {
|
||||
return newAlreadyOwnedError(object, r)
|
||||
}
|
||||
}
|
||||
if fi == -1 {
|
||||
existingRefs = append(existingRefs, ref)
|
||||
} else {
|
||||
existingRefs[fi] = ref
|
||||
}
|
||||
|
||||
// Update owner references
|
||||
object.SetOwnerReferences(existingRefs)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Returns true if a and b point to the same object
|
||||
func referSameObject(a, b v1.OwnerReference) bool {
|
||||
aGV, err := schema.ParseGroupVersion(a.APIVersion)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
bGV, err := schema.ParseGroupVersion(b.APIVersion)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return aGV == bGV && a.Kind == b.Kind && a.Name == b.Name
|
||||
}
|
||||
|
||||
// OperationResult is the action result of a CreateOrUpdate call
|
||||
type OperationResult string
|
||||
|
||||
const ( // They should complete the sentence "Deployment default/foo has been ..."
|
||||
// OperationResultNone means that the resource has not been changed
|
||||
OperationResultNone OperationResult = "unchanged"
|
||||
// OperationResultCreated means that a new resource is created
|
||||
OperationResultCreated OperationResult = "created"
|
||||
// OperationResultUpdated means that an existing resource is updated
|
||||
OperationResultUpdated OperationResult = "updated"
|
||||
)
|
||||
|
||||
// CreateOrUpdate creates or updates the given object obj in the Kubernetes
|
||||
// cluster. The object's desired state should be reconciled with the existing
|
||||
// state using the passed in ReconcileFn. obj must be a struct pointer so that
|
||||
// obj can be updated with the content returned by the Server.
|
||||
//
|
||||
// It returns the executed operation and an error.
|
||||
func CreateOrUpdate(ctx context.Context, c client.Client, obj runtime.Object, f MutateFn) (OperationResult, error) {
|
||||
// op is the operation we are going to attempt
|
||||
op := OperationResultNone
|
||||
|
||||
// get the existing object meta
|
||||
metaObj, ok := obj.(v1.Object)
|
||||
if !ok {
|
||||
return OperationResultNone, fmt.Errorf("%T does not implement metav1.Object interface", obj)
|
||||
}
|
||||
|
||||
// retrieve the existing object
|
||||
key := client.ObjectKey{
|
||||
Name: metaObj.GetName(),
|
||||
Namespace: metaObj.GetNamespace(),
|
||||
}
|
||||
err := c.Get(ctx, key, obj)
|
||||
|
||||
// reconcile the existing object
|
||||
existing := obj.DeepCopyObject()
|
||||
existingObjMeta := existing.(v1.Object)
|
||||
existingObjMeta.SetName(metaObj.GetName())
|
||||
existingObjMeta.SetNamespace(metaObj.GetNamespace())
|
||||
|
||||
if e := f(obj); e != nil {
|
||||
return OperationResultNone, e
|
||||
}
|
||||
|
||||
if metaObj.GetName() != existingObjMeta.GetName() {
|
||||
return OperationResultNone, fmt.Errorf("ReconcileFn cannot mutate objects name")
|
||||
}
|
||||
|
||||
if metaObj.GetNamespace() != existingObjMeta.GetNamespace() {
|
||||
return OperationResultNone, fmt.Errorf("ReconcileFn cannot mutate objects namespace")
|
||||
}
|
||||
|
||||
if errors.IsNotFound(err) {
|
||||
err = c.Create(ctx, obj)
|
||||
op = OperationResultCreated
|
||||
} else if err == nil {
|
||||
if reflect.DeepEqual(existing, obj) {
|
||||
return OperationResultNone, nil
|
||||
}
|
||||
err = c.Update(ctx, obj)
|
||||
op = OperationResultUpdated
|
||||
} else {
|
||||
return OperationResultNone, err
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
op = OperationResultNone
|
||||
}
|
||||
return op, err
|
||||
}
|
||||
|
||||
// MutateFn is a function which mutates the existing object into it's desired state.
|
||||
type MutateFn func(existing runtime.Object) error
|
||||
20
vendor/sigs.k8s.io/controller-runtime/pkg/controller/controllerutil/doc.go
generated
vendored
Normal file
20
vendor/sigs.k8s.io/controller-runtime/pkg/controller/controllerutil/doc.go
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
Copyright 2018 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 controllerutil contains utility functions for working with and implementing Controllers.
|
||||
*/
|
||||
package controllerutil
|
||||
25
vendor/sigs.k8s.io/controller-runtime/pkg/controller/doc.go
generated
vendored
Normal file
25
vendor/sigs.k8s.io/controller-runtime/pkg/controller/doc.go
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
Copyright 2018 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 controller provides types and functions for building Controllers. Controllers implement Kubernetes APIs.
|
||||
|
||||
Creation
|
||||
|
||||
To create a new Controller, first create a manager.Manager and pass it to the controller.New function.
|
||||
The Controller MUST be started by calling Manager.Start.
|
||||
*/
|
||||
package controller
|
||||
Reference in New Issue
Block a user