def _EnsureResources(self): if self.container.resources is not None: if self.container.resources.limits is None: self.container.resources.limits = k8s_object.InitializedInstance( self._messages.ResourceRequirements.LimitsValue) return else: self.container.resources = k8s_object.InitializedInstance( self._messages.ResourceRequirements)
def _EnsureResources(self): limits_cls = self._messages.ResourceRequirements.LimitsValue if self.container.resources is not None: if self.container.resources.limits is None: self.container.resources.limits = k8s_object.InitializedInstance( limits_cls) else: self.container.resources = k8s_object.InitializedInstance( self._messages.ResourceRequirements) # These fields are in the schema due to an error in interperetation of the # Knative spec. We're removing them, so never send any contents for them. self.container.resources.limitsInMap = None self.container.resources.requestsInMap = None
def _EnsureResources(self): limits_cls = self._messages.ResourceRequirements.LimitsValue if self.container.resources is not None: if self.container.resources.limits is None: self.container.resources.limits = k8s_object.InitializedInstance( limits_cls) else: self.container.resources = k8s_object.InitializedInstance( self._messages.ResourceRequirements) # These fields are in the schema due to an error in interperetation of the # Knative spec. We're removing them, so never send any contents for them. try: self.container.resources.limitsInMap = None self.container.resources.requestsInMap = None except AttributeError: # The fields only exist in the v1alpha1 spec, if we're working with a # different version, this is safe to ignore pass
def testNeverLimitsInMap(self): resource_cls = self.serverless_messages.ResourceRequirements self.conf.container.resources = k8s_object.InitializedInstance(resource_cls) self.conf.resource_limits['memory'] = '512Mi' self.assertIsNone(self.conf.container.resources.limitsInMap) self.assertIsNone(self.conf.container.resources.requestsInMap) self.conf.container.resources.limits = None self.conf.resource_limits['memory'] = '512Mi' self.assertIsNone(self.conf.container.resources.limitsInMap) self.assertIsNone(self.conf.container.resources.requestsInMap)
def _EnsureResources(self): limits_cls = self._messages.ResourceRequirements.LimitsValue if self.container.resources is not None: if self.container.resources.limits is None: self.container.resources.limits = k8s_object.InitializedInstance( limits_cls) # If we still have the old field set, move it over to the new. # But if we had both fields, don't bother changing the limits field. if self.container.resources.limitsInMap is not None: for item in self.container.resources.limitsInMap.additionalProperties: self.container.resources.limits.additionalProperties.append( limits_cls.AdditionalProperty( key=item.key, value=item.value.string)) self.container.resources.limitsInMap = None return else: self.container.resources = k8s_object.InitializedInstance( self._messages.ResourceRequirements)
def _EnsureResources(self): limits_in_map_val_cls = self._messages.ResourceRequirements.LimitsInMapValue if self.container.resources is not None: if self.container.resources.limitsInMap is None: self.container.resources.limitsInMap = k8s_object.InitializedInstance( limits_in_map_val_cls) # If we still have the old field set, move it over to the new. # But if we had both fields, don't bother changing the limits field. # TODO(b/120158326) Translate the other way when the new format is ready if self.container.resources.limits is not None: for item in self.container.resources.limits.additionalProperties: self.container.resources.limitsInMap.additionalProperties.append( limits_in_map_val_cls.AdditionalProperty( key=item.key, value=item.value)) self.container.resources.limits = None return else: self.container.resources = k8s_object.InitializedInstance( self._messages.ResourceRequirements)
def _EnsureResources(self): limits_cls = self._messages.ResourceRequirements.LimitsValue if self.container.resources is not None: if self.container.resources.limits is None: self.container.resources.limits = k8s_object.InitializedInstance( limits_cls) # If we still have the old field set, move it over to the new. # But if we had both fields, don't bother changing the limits field. if self.container.resources.limitsInMap is not None: for item in self.container.resources.limitsInMap.additionalProperties: self.container.resources.limits.additionalProperties.append( limits_cls.AdditionalProperty( key=item.key, value=item.value.string)) else: self.container.resources = k8s_object.InitializedInstance( self._messages.ResourceRequirements) # These fields are in the schema due to an error in interperetation of the # Knative spec. We're removing them, so never send any contents for them. self.container.resources.limitsInMap = None self.container.resources.requestsInMap = None
def _EnsureBuild(self): if self._m.spec.build: build = self._m.spec.build if len( list( filter(bool, [ build.source.gcs, build.source.custom, build.source.git ]))) > 1: raise ValueError('Only one build source may be set.') return build = k8s_object.InitializedInstance(self._messages.BuildSpec) build.source.custom = None build.source.git = None self._m.spec.build = build