mirror of
https://github.com/kubernetes/client-go.git
synced 2025-07-31 23:00:26 +00:00
Merge pull request #85899 from gongguan/slim_down_lister
slim down some lister expansions Kubernetes-commit: fcc35b046860ab03851b53ff34a10f6ee0cdecf9
This commit is contained in:
commit
3922ef2909
@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
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 v1
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
apps "k8s.io/api/apps/v1"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DeploymentListerExpansion allows custom methods to be added to
|
|
||||||
// DeploymentLister.
|
|
||||||
type DeploymentListerExpansion interface {
|
|
||||||
GetDeploymentsForReplicaSet(rs *apps.ReplicaSet) ([]*apps.Deployment, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeploymentNamespaceListerExpansion allows custom methods to be added to
|
|
||||||
// DeploymentNamespaceLister.
|
|
||||||
type DeploymentNamespaceListerExpansion interface{}
|
|
||||||
|
|
||||||
// GetDeploymentsForReplicaSet returns a list of Deployments that potentially
|
|
||||||
// match a ReplicaSet. Only the one specified in the ReplicaSet's ControllerRef
|
|
||||||
// will actually manage it.
|
|
||||||
// Returns an error only if no matching Deployments are found.
|
|
||||||
func (s *deploymentLister) GetDeploymentsForReplicaSet(rs *apps.ReplicaSet) ([]*apps.Deployment, error) {
|
|
||||||
if len(rs.Labels) == 0 {
|
|
||||||
return nil, fmt.Errorf("no deployments found for ReplicaSet %v because it has no labels", rs.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: MODIFY THIS METHOD so that it checks for the podTemplateSpecHash label
|
|
||||||
dList, err := s.Deployments(rs.Namespace).List(labels.Everything())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var deployments []*apps.Deployment
|
|
||||||
for _, d := range dList {
|
|
||||||
selector, err := metav1.LabelSelectorAsSelector(d.Spec.Selector)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid label selector: %v", err)
|
|
||||||
}
|
|
||||||
// If a deployment with a nil or empty selector creeps in, it should match nothing, not everything.
|
|
||||||
if selector.Empty() || !selector.Matches(labels.Set(rs.Labels)) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
deployments = append(deployments, d)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(deployments) == 0 {
|
|
||||||
return nil, fmt.Errorf("could not find deployments set for ReplicaSet %s in namespace %s with labels: %v", rs.Name, rs.Namespace, rs.Labels)
|
|
||||||
}
|
|
||||||
|
|
||||||
return deployments, nil
|
|
||||||
}
|
|
@ -25,3 +25,11 @@ type ControllerRevisionListerExpansion interface{}
|
|||||||
// ControllerRevisionNamespaceListerExpansion allows custom methods to be added to
|
// ControllerRevisionNamespaceListerExpansion allows custom methods to be added to
|
||||||
// ControllerRevisionNamespaceLister.
|
// ControllerRevisionNamespaceLister.
|
||||||
type ControllerRevisionNamespaceListerExpansion interface{}
|
type ControllerRevisionNamespaceListerExpansion interface{}
|
||||||
|
|
||||||
|
// DeploymentListerExpansion allows custom methods to be added to
|
||||||
|
// DeploymentLister.
|
||||||
|
type DeploymentListerExpansion interface{}
|
||||||
|
|
||||||
|
// DeploymentNamespaceListerExpansion allows custom methods to be added to
|
||||||
|
// DeploymentNamespaceLister.
|
||||||
|
type DeploymentNamespaceListerExpansion interface{}
|
||||||
|
@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
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 v1beta2
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
apps "k8s.io/api/apps/v1beta2"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DeploymentListerExpansion allows custom methods to be added to
|
|
||||||
// DeploymentLister.
|
|
||||||
type DeploymentListerExpansion interface {
|
|
||||||
GetDeploymentsForReplicaSet(rs *apps.ReplicaSet) ([]*apps.Deployment, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeploymentNamespaceListerExpansion allows custom methods to be added to
|
|
||||||
// DeploymentNamespaceLister.
|
|
||||||
type DeploymentNamespaceListerExpansion interface{}
|
|
||||||
|
|
||||||
// GetDeploymentsForReplicaSet returns a list of Deployments that potentially
|
|
||||||
// match a ReplicaSet. Only the one specified in the ReplicaSet's ControllerRef
|
|
||||||
// will actually manage it.
|
|
||||||
// Returns an error only if no matching Deployments are found.
|
|
||||||
func (s *deploymentLister) GetDeploymentsForReplicaSet(rs *apps.ReplicaSet) ([]*apps.Deployment, error) {
|
|
||||||
if len(rs.Labels) == 0 {
|
|
||||||
return nil, fmt.Errorf("no deployments found for ReplicaSet %v because it has no labels", rs.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: MODIFY THIS METHOD so that it checks for the podTemplateSpecHash label
|
|
||||||
dList, err := s.Deployments(rs.Namespace).List(labels.Everything())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var deployments []*apps.Deployment
|
|
||||||
for _, d := range dList {
|
|
||||||
selector, err := metav1.LabelSelectorAsSelector(d.Spec.Selector)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid label selector: %v", err)
|
|
||||||
}
|
|
||||||
// If a deployment with a nil or empty selector creeps in, it should match nothing, not everything.
|
|
||||||
if selector.Empty() || !selector.Matches(labels.Set(rs.Labels)) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
deployments = append(deployments, d)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(deployments) == 0 {
|
|
||||||
return nil, fmt.Errorf("could not find deployments set for ReplicaSet %s in namespace %s with labels: %v", rs.Name, rs.Namespace, rs.Labels)
|
|
||||||
}
|
|
||||||
|
|
||||||
return deployments, nil
|
|
||||||
}
|
|
@ -25,3 +25,11 @@ type ControllerRevisionListerExpansion interface{}
|
|||||||
// ControllerRevisionNamespaceListerExpansion allows custom methods to be added to
|
// ControllerRevisionNamespaceListerExpansion allows custom methods to be added to
|
||||||
// ControllerRevisionNamespaceLister.
|
// ControllerRevisionNamespaceLister.
|
||||||
type ControllerRevisionNamespaceListerExpansion interface{}
|
type ControllerRevisionNamespaceListerExpansion interface{}
|
||||||
|
|
||||||
|
// DeploymentListerExpansion allows custom methods to be added to
|
||||||
|
// DeploymentLister.
|
||||||
|
type DeploymentListerExpansion interface{}
|
||||||
|
|
||||||
|
// DeploymentNamespaceListerExpansion allows custom methods to be added to
|
||||||
|
// DeploymentNamespaceLister.
|
||||||
|
type DeploymentNamespaceListerExpansion interface{}
|
||||||
|
@ -58,6 +58,10 @@ type LimitRangeNamespaceListerExpansion interface{}
|
|||||||
// NamespaceLister.
|
// NamespaceLister.
|
||||||
type NamespaceListerExpansion interface{}
|
type NamespaceListerExpansion interface{}
|
||||||
|
|
||||||
|
// NodeListerExpansion allows custom methods to be added to
|
||||||
|
// NodeLister.
|
||||||
|
type NodeListerExpansion interface{}
|
||||||
|
|
||||||
// PersistentVolumeListerExpansion allows custom methods to be added to
|
// PersistentVolumeListerExpansion allows custom methods to be added to
|
||||||
// PersistentVolumeLister.
|
// PersistentVolumeLister.
|
||||||
type PersistentVolumeListerExpansion interface{}
|
type PersistentVolumeListerExpansion interface{}
|
||||||
@ -102,6 +106,14 @@ type SecretListerExpansion interface{}
|
|||||||
// SecretNamespaceLister.
|
// SecretNamespaceLister.
|
||||||
type SecretNamespaceListerExpansion interface{}
|
type SecretNamespaceListerExpansion interface{}
|
||||||
|
|
||||||
|
// ServiceListerExpansion allows custom methods to be added to
|
||||||
|
// ServiceLister.
|
||||||
|
type ServiceListerExpansion interface{}
|
||||||
|
|
||||||
|
// ServiceNamespaceListerExpansion allows custom methods to be added to
|
||||||
|
// ServiceNamespaceLister.
|
||||||
|
type ServiceNamespaceListerExpansion interface{}
|
||||||
|
|
||||||
// ServiceAccountListerExpansion allows custom methods to be added to
|
// ServiceAccountListerExpansion allows custom methods to be added to
|
||||||
// ServiceAccountLister.
|
// ServiceAccountLister.
|
||||||
type ServiceAccountListerExpansion interface{}
|
type ServiceAccountListerExpansion interface{}
|
||||||
|
@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
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 v1
|
|
||||||
|
|
||||||
import (
|
|
||||||
"k8s.io/api/core/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NodeConditionPredicate is a function that indicates whether the given node's conditions meet
|
|
||||||
// some set of criteria defined by the function.
|
|
||||||
type NodeConditionPredicate func(node *v1.Node) bool
|
|
||||||
|
|
||||||
// NodeListerExpansion allows custom methods to be added to
|
|
||||||
// NodeLister.
|
|
||||||
type NodeListerExpansion interface {
|
|
||||||
ListWithPredicate(predicate NodeConditionPredicate) ([]*v1.Node, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *nodeLister) ListWithPredicate(predicate NodeConditionPredicate) ([]*v1.Node, error) {
|
|
||||||
nodes, err := l.List(labels.Everything())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var filtered []*v1.Node
|
|
||||||
for i := range nodes {
|
|
||||||
if predicate(nodes[i]) {
|
|
||||||
filtered = append(filtered, nodes[i])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return filtered, nil
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
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 v1
|
|
||||||
|
|
||||||
import (
|
|
||||||
"k8s.io/api/core/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ServiceListerExpansion allows custom methods to be added to
|
|
||||||
// ServiceLister.
|
|
||||||
type ServiceListerExpansion interface {
|
|
||||||
GetPodServices(pod *v1.Pod) ([]*v1.Service, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ServiceNamespaceListerExpansion allows custom methods to be added to
|
|
||||||
// ServiceNamespaceLister.
|
|
||||||
type ServiceNamespaceListerExpansion interface{}
|
|
||||||
|
|
||||||
// TODO: Move this back to scheduler as a helper function that takes a Store,
|
|
||||||
// rather than a method of ServiceLister.
|
|
||||||
func (s *serviceLister) GetPodServices(pod *v1.Pod) ([]*v1.Service, error) {
|
|
||||||
allServices, err := s.Services(pod.Namespace).List(labels.Everything())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var services []*v1.Service
|
|
||||||
for i := range allServices {
|
|
||||||
service := allServices[i]
|
|
||||||
if service.Spec.Selector == nil {
|
|
||||||
// services with nil selectors match nothing, not everything.
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
selector := labels.Set(service.Spec.Selector).AsSelectorPreValidated()
|
|
||||||
if selector.Matches(labels.Set(pod.Labels)) {
|
|
||||||
services = append(services, service)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return services, nil
|
|
||||||
}
|
|
@ -1,70 +0,0 @@
|
|||||||
/*
|
|
||||||
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 v1beta1
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
extensions "k8s.io/api/extensions/v1beta1"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DeploymentListerExpansion allows custom methods to be added to
|
|
||||||
// DeploymentLister.
|
|
||||||
type DeploymentListerExpansion interface {
|
|
||||||
GetDeploymentsForReplicaSet(rs *extensions.ReplicaSet) ([]*extensions.Deployment, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DeploymentNamespaceListerExpansion allows custom methods to be added to
|
|
||||||
// DeploymentNamespaceLister.
|
|
||||||
type DeploymentNamespaceListerExpansion interface{}
|
|
||||||
|
|
||||||
// GetDeploymentsForReplicaSet returns a list of Deployments that potentially
|
|
||||||
// match a ReplicaSet. Only the one specified in the ReplicaSet's ControllerRef
|
|
||||||
// will actually manage it.
|
|
||||||
// Returns an error only if no matching Deployments are found.
|
|
||||||
func (s *deploymentLister) GetDeploymentsForReplicaSet(rs *extensions.ReplicaSet) ([]*extensions.Deployment, error) {
|
|
||||||
if len(rs.Labels) == 0 {
|
|
||||||
return nil, fmt.Errorf("no deployments found for ReplicaSet %v because it has no labels", rs.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: MODIFY THIS METHOD so that it checks for the podTemplateSpecHash label
|
|
||||||
dList, err := s.Deployments(rs.Namespace).List(labels.Everything())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var deployments []*extensions.Deployment
|
|
||||||
for _, d := range dList {
|
|
||||||
selector, err := metav1.LabelSelectorAsSelector(d.Spec.Selector)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("invalid label selector: %v", err)
|
|
||||||
}
|
|
||||||
// If a deployment with a nil or empty selector creeps in, it should match nothing, not everything.
|
|
||||||
if selector.Empty() || !selector.Matches(labels.Set(rs.Labels)) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
deployments = append(deployments, d)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(deployments) == 0 {
|
|
||||||
return nil, fmt.Errorf("could not find deployments set for ReplicaSet %s in namespace %s with labels: %v", rs.Name, rs.Namespace, rs.Labels)
|
|
||||||
}
|
|
||||||
|
|
||||||
return deployments, nil
|
|
||||||
}
|
|
@ -18,6 +18,14 @@ limitations under the License.
|
|||||||
|
|
||||||
package v1beta1
|
package v1beta1
|
||||||
|
|
||||||
|
// DeploymentListerExpansion allows custom methods to be added to
|
||||||
|
// DeploymentLister.
|
||||||
|
type DeploymentListerExpansion interface{}
|
||||||
|
|
||||||
|
// DeploymentNamespaceListerExpansion allows custom methods to be added to
|
||||||
|
// DeploymentNamespaceLister.
|
||||||
|
type DeploymentNamespaceListerExpansion interface{}
|
||||||
|
|
||||||
// IngressListerExpansion allows custom methods to be added to
|
// IngressListerExpansion allows custom methods to be added to
|
||||||
// IngressLister.
|
// IngressLister.
|
||||||
type IngressListerExpansion interface{}
|
type IngressListerExpansion interface{}
|
||||||
|
Loading…
Reference in New Issue
Block a user