| 
									
										
										
										
											2014-10-07 22:24:40 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | Copyright 2014 Google Inc. 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 api | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"strings" | 
					
						
							| 
									
										
										
										
											2015-01-06 05:38:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource" | 
					
						
							|  |  |  | 	"github.com/GoogleCloudPlatform/kubernetes/pkg/conversion" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Semantic can do semantic deep equality checks for api objects.
 | 
					
						
							|  |  |  | // Example: api.Semantic.DeepEqual(aPod, aPodWithNonNilButEmptyMaps) == true
 | 
					
						
							|  |  |  | var Semantic = conversion.EqualitiesOrDie( | 
					
						
							|  |  |  | 	func(a, b resource.Quantity) bool { | 
					
						
							|  |  |  | 		// Ignore formatting, only care that numeric value stayed the same.
 | 
					
						
							|  |  |  | 		// TODO: if we decide it's important, after we drop v1beta1/2, we
 | 
					
						
							|  |  |  | 		// could start comparing format.
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 		// Uninitialized quantities are equivilent to 0 quantities.
 | 
					
						
							|  |  |  | 		if a.Amount == nil && b.MilliValue() == 0 { | 
					
						
							|  |  |  | 			return true | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if b.Amount == nil && a.MilliValue() == 0 { | 
					
						
							|  |  |  | 			return true | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return a.Amount.Cmp(b.Amount) == 0 | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2014-10-07 22:24:40 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-11 15:11:45 +08:00
										 |  |  | // TODO: Address these per #1502
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-07 22:24:40 +08:00
										 |  |  | func IsPullAlways(p PullPolicy) bool { | 
					
						
							|  |  |  | 	return pullPoliciesEqual(p, PullAlways) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func IsPullNever(p PullPolicy) bool { | 
					
						
							|  |  |  | 	return pullPoliciesEqual(p, PullNever) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func IsPullIfNotPresent(p PullPolicy) bool { | 
					
						
							| 
									
										
										
										
											2014-11-14 07:23:44 +08:00
										 |  |  | 	// Default to pull if not present
 | 
					
						
							|  |  |  | 	if len(p) == 0 { | 
					
						
							|  |  |  | 		return true | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-10-07 22:24:40 +08:00
										 |  |  | 	return pullPoliciesEqual(p, PullIfNotPresent) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func pullPoliciesEqual(p1, p2 PullPolicy) bool { | 
					
						
							|  |  |  | 	return strings.ToLower(string(p1)) == strings.ToLower(string(p2)) | 
					
						
							|  |  |  | } |