mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Define PodDisruption API types.
This commit is contained in:
		@@ -45,6 +45,8 @@ func main() {
 | 
				
			|||||||
		"k8s.io/kubernetes/pkg/apis/apps/v1alpha1",
 | 
							"k8s.io/kubernetes/pkg/apis/apps/v1alpha1",
 | 
				
			||||||
		"k8s.io/kubernetes/pkg/apis/componentconfig",
 | 
							"k8s.io/kubernetes/pkg/apis/componentconfig",
 | 
				
			||||||
		"k8s.io/kubernetes/pkg/apis/componentconfig/v1alpha1",
 | 
							"k8s.io/kubernetes/pkg/apis/componentconfig/v1alpha1",
 | 
				
			||||||
 | 
							"k8s.io/kubernetes/pkg/apis/policy",
 | 
				
			||||||
 | 
							"k8s.io/kubernetes/pkg/apis/policy/v1alpha1",
 | 
				
			||||||
		"k8s.io/kubernetes/pkg/apis/extensions",
 | 
							"k8s.io/kubernetes/pkg/apis/extensions",
 | 
				
			||||||
		"k8s.io/kubernetes/pkg/apis/extensions/v1beta1",
 | 
							"k8s.io/kubernetes/pkg/apis/extensions/v1beta1",
 | 
				
			||||||
		"k8s.io/kubernetes/pkg/apis/metrics",
 | 
							"k8s.io/kubernetes/pkg/apis/metrics",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -45,6 +45,8 @@ func main() {
 | 
				
			|||||||
		"k8s.io/kubernetes/pkg/apis/apps/v1alpha1",
 | 
							"k8s.io/kubernetes/pkg/apis/apps/v1alpha1",
 | 
				
			||||||
		"k8s.io/kubernetes/pkg/apis/componentconfig",
 | 
							"k8s.io/kubernetes/pkg/apis/componentconfig",
 | 
				
			||||||
		"k8s.io/kubernetes/pkg/apis/componentconfig/v1alpha1",
 | 
							"k8s.io/kubernetes/pkg/apis/componentconfig/v1alpha1",
 | 
				
			||||||
 | 
							"k8s.io/kubernetes/pkg/apis/policy",
 | 
				
			||||||
 | 
							"k8s.io/kubernetes/pkg/apis/policy/v1alpha1",
 | 
				
			||||||
		"k8s.io/kubernetes/pkg/apis/extensions",
 | 
							"k8s.io/kubernetes/pkg/apis/extensions",
 | 
				
			||||||
		"k8s.io/kubernetes/pkg/apis/extensions/v1beta1",
 | 
							"k8s.io/kubernetes/pkg/apis/extensions/v1beta1",
 | 
				
			||||||
		"k8s.io/kubernetes/pkg/apis/metrics",
 | 
							"k8s.io/kubernetes/pkg/apis/metrics",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -66,6 +66,7 @@ func New() *Generator {
 | 
				
			|||||||
			`+k8s.io/kubernetes/pkg/watch/versioned`,
 | 
								`+k8s.io/kubernetes/pkg/watch/versioned`,
 | 
				
			||||||
			`k8s.io/kubernetes/pkg/api/unversioned`,
 | 
								`k8s.io/kubernetes/pkg/api/unversioned`,
 | 
				
			||||||
			`k8s.io/kubernetes/pkg/api/v1`,
 | 
								`k8s.io/kubernetes/pkg/api/v1`,
 | 
				
			||||||
 | 
								`k8s.io/kubernetes/pkg/apis/policy/v1alpha1`,
 | 
				
			||||||
			`k8s.io/kubernetes/pkg/apis/extensions/v1beta1`,
 | 
								`k8s.io/kubernetes/pkg/apis/extensions/v1beta1`,
 | 
				
			||||||
			`k8s.io/kubernetes/pkg/apis/autoscaling/v1`,
 | 
								`k8s.io/kubernetes/pkg/apis/autoscaling/v1`,
 | 
				
			||||||
			`k8s.io/kubernetes/pkg/apis/batch/v1`,
 | 
								`k8s.io/kubernetes/pkg/apis/batch/v1`,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -58,7 +58,7 @@ KUBE_GOVERALLS_BIN=${KUBE_GOVERALLS_BIN:-}
 | 
				
			|||||||
# Lists of API Versions of each groups that should be tested, groups are
 | 
					# Lists of API Versions of each groups that should be tested, groups are
 | 
				
			||||||
# separated by comma, lists are separated by semicolon. e.g.,
 | 
					# separated by comma, lists are separated by semicolon. e.g.,
 | 
				
			||||||
# "v1,compute/v1alpha1,experimental/v1alpha2;v1,compute/v2,experimental/v1alpha3"
 | 
					# "v1,compute/v1alpha1,experimental/v1alpha2;v1,compute/v2,experimental/v1alpha3"
 | 
				
			||||||
KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,extensions/v1beta1,metrics/v1alpha1,federation/v1alpha1;v1,autoscaling/v1,batch/v1,extensions/v1beta1,apps/v1alpha1,metrics/v1alpha1,federation/v1alpha1"}
 | 
					KUBE_TEST_API_VERSIONS=${KUBE_TEST_API_VERSIONS:-"v1,extensions/v1beta1,metrics/v1alpha1,federation/v1alpha1;v1,autoscaling/v1,batch/v1,extensions/v1beta1,apps/v1alpha1,metrics/v1alpha1,federation/v1alpha1,policy/v1alpha1"}
 | 
				
			||||||
# once we have multiple group supports
 | 
					# once we have multiple group supports
 | 
				
			||||||
# Run tests with the standard (registry) and a custom etcd prefix
 | 
					# Run tests with the standard (registry) and a custom etcd prefix
 | 
				
			||||||
# (kubernetes.io/registry).
 | 
					# (kubernetes.io/registry).
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										129
									
								
								pkg/apis/policy/install/install.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										129
									
								
								pkg/apis/policy/install/install.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,129 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					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 install installs the experimental API group, making it available as
 | 
				
			||||||
 | 
					// an option to all of the API encoding/decoding machinery.
 | 
				
			||||||
 | 
					package install
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/golang/glog"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/api"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/api/meta"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/api/unversioned"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/apimachinery"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/apimachinery/registered"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/apis/policy"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/apis/policy/v1alpha1"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/runtime"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/util/sets"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const importPrefix = "k8s.io/kubernetes/pkg/apis/policy"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var accessor = meta.NewAccessor()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// availableVersions lists all known external versions for this group from most preferred to least preferred
 | 
				
			||||||
 | 
					var availableVersions = []unversioned.GroupVersion{v1alpha1.SchemeGroupVersion}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func init() {
 | 
				
			||||||
 | 
						registered.RegisterVersions(availableVersions)
 | 
				
			||||||
 | 
						externalVersions := []unversioned.GroupVersion{}
 | 
				
			||||||
 | 
						for _, v := range availableVersions {
 | 
				
			||||||
 | 
							if registered.IsAllowedVersion(v) {
 | 
				
			||||||
 | 
								externalVersions = append(externalVersions, v)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if len(externalVersions) == 0 {
 | 
				
			||||||
 | 
							glog.V(4).Infof("No version is registered for group %v", policy.GroupName)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := registered.EnableVersions(externalVersions...); err != nil {
 | 
				
			||||||
 | 
							glog.V(4).Infof("%v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						if err := enableVersions(externalVersions); err != nil {
 | 
				
			||||||
 | 
							glog.V(4).Infof("%v", err)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// TODO: enableVersions should be centralized rather than spread in each API
 | 
				
			||||||
 | 
					// group.
 | 
				
			||||||
 | 
					// We can combine registered.RegisterVersions, registered.EnableVersions and
 | 
				
			||||||
 | 
					// registered.RegisterGroup once we have moved enableVersions there.
 | 
				
			||||||
 | 
					func enableVersions(externalVersions []unversioned.GroupVersion) error {
 | 
				
			||||||
 | 
						addVersionsToScheme(externalVersions...)
 | 
				
			||||||
 | 
						preferredExternalVersion := externalVersions[0]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						groupMeta := apimachinery.GroupMeta{
 | 
				
			||||||
 | 
							GroupVersion:  preferredExternalVersion,
 | 
				
			||||||
 | 
							GroupVersions: externalVersions,
 | 
				
			||||||
 | 
							RESTMapper:    newRESTMapper(externalVersions),
 | 
				
			||||||
 | 
							SelfLinker:    runtime.SelfLinker(accessor),
 | 
				
			||||||
 | 
							InterfacesFor: interfacesFor,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err := registered.RegisterGroup(groupMeta); err != nil {
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						api.RegisterRESTMapper(groupMeta.RESTMapper)
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func newRESTMapper(externalVersions []unversioned.GroupVersion) meta.RESTMapper {
 | 
				
			||||||
 | 
						// the list of kinds that are scoped at the root of the api hierarchy
 | 
				
			||||||
 | 
						// if a kind is not enumerated here, it is assumed to have a namespace scope
 | 
				
			||||||
 | 
						rootScoped := sets.NewString()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ignoredKinds := sets.NewString()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return api.NewDefaultRESTMapper(externalVersions, interfacesFor, importPrefix, ignoredKinds, rootScoped)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// interfacesFor returns the default Codec and ResourceVersioner for a given version
 | 
				
			||||||
 | 
					// string, or an error if the version is not known.
 | 
				
			||||||
 | 
					func interfacesFor(version unversioned.GroupVersion) (*meta.VersionInterfaces, error) {
 | 
				
			||||||
 | 
						switch version {
 | 
				
			||||||
 | 
						case v1alpha1.SchemeGroupVersion:
 | 
				
			||||||
 | 
							return &meta.VersionInterfaces{
 | 
				
			||||||
 | 
								ObjectConvertor:  api.Scheme,
 | 
				
			||||||
 | 
								MetadataAccessor: accessor,
 | 
				
			||||||
 | 
							}, nil
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							g, _ := registered.Group(policy.GroupName)
 | 
				
			||||||
 | 
							return nil, fmt.Errorf("unsupported storage version: %s (valid: %v)", version, g.GroupVersions)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func addVersionsToScheme(externalVersions ...unversioned.GroupVersion) {
 | 
				
			||||||
 | 
						// add the internal version to Scheme
 | 
				
			||||||
 | 
						policy.AddToScheme(api.Scheme)
 | 
				
			||||||
 | 
						// add the enabled external versions to Scheme
 | 
				
			||||||
 | 
						for _, v := range externalVersions {
 | 
				
			||||||
 | 
							if !registered.IsEnabledVersion(v) {
 | 
				
			||||||
 | 
								glog.Errorf("Version %s is not enabled, so it will not be added to the Scheme.", v)
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							switch v {
 | 
				
			||||||
 | 
							case v1alpha1.SchemeGroupVersion:
 | 
				
			||||||
 | 
								v1alpha1.AddToScheme(api.Scheme)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										53
									
								
								pkg/apis/policy/register.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								pkg/apis/policy/register.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,53 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					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 policy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/api/unversioned"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/runtime"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GroupName is the group name use in this package
 | 
				
			||||||
 | 
					const GroupName = "policy"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// SchemeGroupVersion is group version used to register these objects
 | 
				
			||||||
 | 
					var SchemeGroupVersion = unversioned.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Kind takes an unqualified kind and returns back a Group qualified GroupKind
 | 
				
			||||||
 | 
					func Kind(kind string) unversioned.GroupKind {
 | 
				
			||||||
 | 
						return SchemeGroupVersion.WithKind(kind).GroupKind()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Resource takes an unqualified resource and returns back a Group qualified GroupResource
 | 
				
			||||||
 | 
					func Resource(resource string) unversioned.GroupResource {
 | 
				
			||||||
 | 
						return SchemeGroupVersion.WithResource(resource).GroupResource()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func AddToScheme(scheme *runtime.Scheme) {
 | 
				
			||||||
 | 
						// Add the API to Scheme.
 | 
				
			||||||
 | 
						addKnownTypes(scheme)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Adds the list of known types to api.Scheme.
 | 
				
			||||||
 | 
					func addKnownTypes(scheme *runtime.Scheme) {
 | 
				
			||||||
 | 
						// TODO this gets cleaned up when the types are fixed
 | 
				
			||||||
 | 
						scheme.AddKnownTypes(SchemeGroupVersion,
 | 
				
			||||||
 | 
							&PodDisruptionBudget{},
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (obj *PodDisruptionBudget) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
 | 
				
			||||||
							
								
								
									
										63
									
								
								pkg/apis/policy/types.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								pkg/apis/policy/types.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,63 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					Copyright 2016 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 policy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/api"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/api/unversioned"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/util/intstr"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// PodDisruptionBudgetSpec is a description of a PodDisruptionBudget.
 | 
				
			||||||
 | 
					type PodDisruptionBudgetSpec struct {
 | 
				
			||||||
 | 
						// The minimum number of pods that must be available simultaneously.  This
 | 
				
			||||||
 | 
						// can be either an integer or a string specifying a percentage, e.g. "28%".
 | 
				
			||||||
 | 
						MinAvailable intstr.IntOrString `json:"minAvailable,omitempty"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Selector is a label query over pods whose evictions are managed by the
 | 
				
			||||||
 | 
						// disruption budget.
 | 
				
			||||||
 | 
						Selector *unversioned.LabelSelector `json:"selector,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// PodDisruptionBudgetStatus represents information about the status of a
 | 
				
			||||||
 | 
					// PodDisruptionBudget. Status may trail the actual state of a system.
 | 
				
			||||||
 | 
					type PodDisruptionBudgetStatus struct {
 | 
				
			||||||
 | 
						// Whether or not a disruption is currently allowed.
 | 
				
			||||||
 | 
						PodDisruptionAllowed bool `json:"disruptionAllowed"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// current number of healthy pods
 | 
				
			||||||
 | 
						CurrentHealthy int32 `json:"currentHealthy"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// minimum desired number of healthy pods
 | 
				
			||||||
 | 
						DesiredHealthy int32 `json:"desiredHealthy"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// total number of pods counted by this disruption budget
 | 
				
			||||||
 | 
						ExpectedPods int32 `json:"expectedPods"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// +genclient=true,noMethods=true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// PodDisruptionBudget is an object to define the max disruption that can be caused to a collection of pods
 | 
				
			||||||
 | 
					type PodDisruptionBudget struct {
 | 
				
			||||||
 | 
						unversioned.TypeMeta `json:",inline"`
 | 
				
			||||||
 | 
						api.ObjectMeta       `json:"metadata,omitempty"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Specification of the desired behavior of the PodDisruptionBudget.
 | 
				
			||||||
 | 
						Spec PodDisruptionBudgetSpec `json:"spec,omitempty"`
 | 
				
			||||||
 | 
						// Most recently observed status of the PodDisruptionBudget.
 | 
				
			||||||
 | 
						Status PodDisruptionBudgetStatus `json:"status,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										21
									
								
								pkg/apis/policy/v1alpha1/doc.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								pkg/apis/policy/v1alpha1/doc.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					Copyright 2016 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 policy is for any kind of policy object.  Suitable examples, even if
 | 
				
			||||||
 | 
					// they aren't all here, are PodDisruptionBudget, PodSecurityPolicy,
 | 
				
			||||||
 | 
					// NetworkPolicy, etc.
 | 
				
			||||||
 | 
					// +genconversion=true
 | 
				
			||||||
 | 
					package v1alpha1
 | 
				
			||||||
							
								
								
									
										48
									
								
								pkg/apis/policy/v1alpha1/register.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								pkg/apis/policy/v1alpha1/register.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,48 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					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 v1alpha1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/api/unversioned"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/runtime"
 | 
				
			||||||
 | 
						versionedwatch "k8s.io/kubernetes/pkg/watch/versioned"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// GroupName is the group name use in this package
 | 
				
			||||||
 | 
					const GroupName = "policy"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// SchemeGroupVersion is group version used to register these objects
 | 
				
			||||||
 | 
					var SchemeGroupVersion = unversioned.GroupVersion{Group: GroupName, Version: "v1alpha1"}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func AddToScheme(scheme *runtime.Scheme) {
 | 
				
			||||||
 | 
						addKnownTypes(scheme)
 | 
				
			||||||
 | 
						/*
 | 
				
			||||||
 | 
							addDefaultingFuncs(scheme)
 | 
				
			||||||
 | 
							addConversionFuncs(scheme)
 | 
				
			||||||
 | 
						*/
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Adds the list of known types to api.Scheme.
 | 
				
			||||||
 | 
					func addKnownTypes(scheme *runtime.Scheme) {
 | 
				
			||||||
 | 
						scheme.AddKnownTypes(SchemeGroupVersion,
 | 
				
			||||||
 | 
							&PodDisruptionBudget{},
 | 
				
			||||||
 | 
						)
 | 
				
			||||||
 | 
						// Add the watch version that applies
 | 
				
			||||||
 | 
						versionedwatch.AddToGroupVersion(scheme, SchemeGroupVersion)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (obj *PodDisruptionBudget) GetObjectKind() unversioned.ObjectKind { return &obj.TypeMeta }
 | 
				
			||||||
							
								
								
									
										64
									
								
								pkg/apis/policy/v1alpha1/types.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								pkg/apis/policy/v1alpha1/types.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,64 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					Copyright 2016 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 v1alpha1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/api/unversioned"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/api/v1"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/util/intstr"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// PodDisruptionBudgetSpec is a description of a PodDisruptionBudget.
 | 
				
			||||||
 | 
					type PodDisruptionBudgetSpec struct {
 | 
				
			||||||
 | 
						// The minimum number of pods that must be available simultaneously.  This
 | 
				
			||||||
 | 
						// can be either an integer or a string specifying a percentage, e.g. "28%".
 | 
				
			||||||
 | 
						MinAvailable intstr.IntOrString `json:"minAvailable,omitempty"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Selector is a label query over pods whose evictions are managed by the
 | 
				
			||||||
 | 
						// disruption budget.
 | 
				
			||||||
 | 
						Selector *unversioned.LabelSelector `json:"selector,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// PodDisruptionBudgetStatus represents information about the status of a
 | 
				
			||||||
 | 
					// PodDisruptionBudget. Status may trail the actual state of a system.
 | 
				
			||||||
 | 
					type PodDisruptionBudgetStatus struct {
 | 
				
			||||||
 | 
						// Whether or not a disruption is currently allowed.
 | 
				
			||||||
 | 
						PodDisruptionAllowed bool `json:"disruptionAllowed"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// current number of healthy pods
 | 
				
			||||||
 | 
						CurrentHealthy int32 `json:"currentHealthy"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// minimum desired number of healthy pods
 | 
				
			||||||
 | 
						DesiredHealthy int32 `json:"desiredHealthy"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// total number of pods counted by this disruption budget
 | 
				
			||||||
 | 
						ExpectedPods int32 `json:"expectedPods"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// +genclient=true,noMethods=true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// PodDisruptionBudget is an object to define the max disruption that can be caused to a collection of pods
 | 
				
			||||||
 | 
					type PodDisruptionBudget struct {
 | 
				
			||||||
 | 
						unversioned.TypeMeta `json:",inline"`
 | 
				
			||||||
 | 
						v1.ObjectMeta        `json:"metadata,omitempty"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Specification of the desired behavior of the PodDisruptionBudget.
 | 
				
			||||||
 | 
						Spec PodDisruptionBudgetSpec `json:"spec,omitempty"`
 | 
				
			||||||
 | 
						// Most recently observed status of the PodDisruptionBudget.
 | 
				
			||||||
 | 
						Status PodDisruptionBudgetStatus `json:"status,omitempty"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										34
									
								
								pkg/apis/policy/validation/validation.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								pkg/apis/policy/validation/validation.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					Copyright 2016 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 validation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						unversionedvalidation "k8s.io/kubernetes/pkg/api/unversioned/validation"
 | 
				
			||||||
 | 
						extensionsvalidation "k8s.io/kubernetes/pkg/apis/extensions/validation"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/apis/policy"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/util/validation/field"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func ValidatePodDisruptionBudgetSpec(spec policy.PodDisruptionBudgetSpec, fldPath *field.Path) field.ErrorList {
 | 
				
			||||||
 | 
						allErrs := field.ErrorList{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						allErrs = append(allErrs, extensionsvalidation.ValidatePositiveIntOrPercent(spec.MinAvailable, fldPath.Child("minAvailable"))...)
 | 
				
			||||||
 | 
						allErrs = append(allErrs, extensionsvalidation.IsNotMoreThan100Percent(spec.MinAvailable, fldPath.Child("minAvailable"))...)
 | 
				
			||||||
 | 
						allErrs = append(allErrs, unversionedvalidation.ValidateLabelSelector(spec.Selector, fldPath.Child("selector"))...)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return allErrs
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										62
									
								
								pkg/apis/policy/validation/validation_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								pkg/apis/policy/validation/validation_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,62 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					Copyright 2016 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 validation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/apis/policy"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/util/intstr"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/util/validation/field"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func TestValidatePodDisruptionBudgetSpec(t *testing.T) {
 | 
				
			||||||
 | 
						successCases := []intstr.IntOrString{
 | 
				
			||||||
 | 
							intstr.FromString("0%"),
 | 
				
			||||||
 | 
							intstr.FromString("1%"),
 | 
				
			||||||
 | 
							intstr.FromString("100%"),
 | 
				
			||||||
 | 
							intstr.FromInt(0),
 | 
				
			||||||
 | 
							intstr.FromInt(1),
 | 
				
			||||||
 | 
							intstr.FromInt(100),
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for _, c := range successCases {
 | 
				
			||||||
 | 
							spec := policy.PodDisruptionBudgetSpec{
 | 
				
			||||||
 | 
								MinAvailable: c,
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							errs := ValidatePodDisruptionBudgetSpec(spec, field.NewPath("foo"))
 | 
				
			||||||
 | 
							if len(errs) != 0 {
 | 
				
			||||||
 | 
								t.Errorf("unexpected failure %v for %v", errs, spec)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						failureCases := []intstr.IntOrString{
 | 
				
			||||||
 | 
							intstr.FromString("1.1%"),
 | 
				
			||||||
 | 
							intstr.FromString("nope"),
 | 
				
			||||||
 | 
							intstr.FromString("-1%"),
 | 
				
			||||||
 | 
							intstr.FromString("101%"),
 | 
				
			||||||
 | 
							intstr.FromInt(-1),
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for _, c := range failureCases {
 | 
				
			||||||
 | 
							spec := policy.PodDisruptionBudgetSpec{
 | 
				
			||||||
 | 
								MinAvailable: c,
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							errs := ValidatePodDisruptionBudgetSpec(spec, field.NewPath("foo"))
 | 
				
			||||||
 | 
							if len(errs) == 0 {
 | 
				
			||||||
 | 
								t.Errorf("unexpected success for %v", spec)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -29,6 +29,7 @@ import (
 | 
				
			|||||||
	_ "k8s.io/kubernetes/pkg/apis/componentconfig/install"
 | 
						_ "k8s.io/kubernetes/pkg/apis/componentconfig/install"
 | 
				
			||||||
	_ "k8s.io/kubernetes/pkg/apis/extensions/install"
 | 
						_ "k8s.io/kubernetes/pkg/apis/extensions/install"
 | 
				
			||||||
	_ "k8s.io/kubernetes/pkg/apis/metrics/install"
 | 
						_ "k8s.io/kubernetes/pkg/apis/metrics/install"
 | 
				
			||||||
 | 
						_ "k8s.io/kubernetes/pkg/apis/policy/install"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func init() {
 | 
					func init() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,6 +28,7 @@ import (
 | 
				
			|||||||
	_ "k8s.io/kubernetes/pkg/apis/batch/install"
 | 
						_ "k8s.io/kubernetes/pkg/apis/batch/install"
 | 
				
			||||||
	_ "k8s.io/kubernetes/pkg/apis/componentconfig/install"
 | 
						_ "k8s.io/kubernetes/pkg/apis/componentconfig/install"
 | 
				
			||||||
	_ "k8s.io/kubernetes/pkg/apis/extensions/install"
 | 
						_ "k8s.io/kubernetes/pkg/apis/extensions/install"
 | 
				
			||||||
 | 
						_ "k8s.io/kubernetes/pkg/apis/policy/install"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func init() {
 | 
					func init() {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user