github.com/spotmaxtech/k8s-apimachinery-v0260@v0.0.1/pkg/api/equality/semantic.go (about)

     1  /*
     2  Copyright 2014 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package equality
    18  
    19  import (
    20  	"github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/api/resource"
    21  	metav1 "github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/apis/meta/v1"
    22  	"github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/conversion"
    23  	"github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/fields"
    24  	"github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/labels"
    25  )
    26  
    27  // Semantic can do semantic deep equality checks for api objects.
    28  // Example: apiequality.Semantic.DeepEqual(aPod, aPodWithNonNilButEmptyMaps) == true
    29  var Semantic = conversion.EqualitiesOrDie(
    30  	func(a, b resource.Quantity) bool {
    31  		// Ignore formatting, only care that numeric value stayed the same.
    32  		// TODO: if we decide it's important, it should be safe to start comparing the format.
    33  		//
    34  		// Uninitialized quantities are equivalent to 0 quantities.
    35  		return a.Cmp(b) == 0
    36  	},
    37  	func(a, b metav1.MicroTime) bool {
    38  		return a.UTC() == b.UTC()
    39  	},
    40  	func(a, b metav1.Time) bool {
    41  		return a.UTC() == b.UTC()
    42  	},
    43  	func(a, b labels.Selector) bool {
    44  		return a.String() == b.String()
    45  	},
    46  	func(a, b fields.Selector) bool {
    47  		return a.String() == b.String()
    48  	},
    49  )