Beispiel #1
0
 def config_maps(self):
     """Mutable dict-like object for volumes with a config map source type."""
     return k8s_object.ListAsDictionaryWrapper(
         self._volumes,
         self._volume_class,
         value_field='configMap',
         filter_func=lambda volume: volume.configMap is not None)
Beispiel #2
0
 def secrets(self):
     """Mutable dict-like object for volumes with a secret source type."""
     return k8s_object.ListAsDictionaryWrapper(
         self._volumes,
         self._volume_class,
         value_field='secret',
         filter_func=lambda volume: volume.secret is not None)
Beispiel #3
0
 def data(self):
     if self._m.data is None:
         self._m.data = self._messages.ConfigMap.DataValue()
     return k8s_object.ListAsDictionaryWrapper(
         self._m.data.additionalProperties,
         self._messages.ConfigMap.DataValue.AdditionalProperty,
         key_field='key',
         value_field='value')
Beispiel #4
0
 def config_maps(self):
     """Mutable dict-like object for mounts whose volumes have a config map source type."""
     return k8s_object.ListAsDictionaryWrapper(
         self._m,
         self._item_class,
         key_field=self._key_field,
         value_field=self._value_field,
         filter_func=lambda mount: mount.name in self._volumes.config_maps)
    def env_vars(self):
        """Returns a mutable, dict-like object to manage env vars.

    The returned object can be used like a dictionary, and any modifications to
    the returned object (i.e. setting and deleting keys) modify the underlying
    nested env vars fields.
    """
        return k8s_object.ListAsDictionaryWrapper(self.container.env,
                                                  self._messages.EnvVar)
 def resource_limits(self):
     """The resource limits as a dictionary { resource name: limit}."""
     self._EnsureResources()
     return k8s_object.ListAsDictionaryWrapper(
         self.container.resources.limits.additionalProperties,
         self._messages.ResourceRequirements.LimitsValue.AdditionalProperty,
         key_field='key',
         value_field='value',
     )
 def revision_labels(self):
     revision_meta = self.spec.revisionTemplate.metadata
     if revision_meta.labels is None:
         revision_meta.labels = self._messages.ObjectMeta.LabelsValue()
     return k8s_object.ListAsDictionaryWrapper(
         revision_meta.labels.additionalProperties,
         self._messages.ObjectMeta.LabelsValue.AdditionalProperty,
         key_field='key',
         value_field='value',
     )
    def testListAsDictionaryWrapperFilterFunc(self):
        def _FilterFunc(obj):
            return obj.value > 2

        wrapped_msgs = k8s_object.ListAsDictionaryWrapper(
            self.messages, FakeMessage, filter_func=_FilterFunc)
        self.assertDictEqual({
            'm3': 3,
            'm4': 4,
        }, dict(wrapped_msgs))
 def testListAsDictionaryWrapperWraps(self):
     wrapped_msgs = k8s_object.ListAsDictionaryWrapper(
         self.messages, FakeMessage)
     self.assertDictEqual({
         'm0': 0,
         'm1': 1,
         'm2': 2,
         'm3': 3,
         'm4': 4,
     }, dict(wrapped_msgs))
Beispiel #10
0
    def secrets(self):
        """Mutable dict-like object for volumes with a secret source type."""
        def _FilterSecretVolumes(volume):
            return volume.secret is not None

        return k8s_object.ListAsDictionaryWrapper(
            self._volumes,
            self._volume_class,
            value_field='secret',
            filter_func=_FilterSecretVolumes)
Beispiel #11
0
    def secrets(self):
        """Mutable dict-like object for mounts whose volumes have a secret source type."""
        def _FilterSecretMounts(mount):
            return mount.name in self._volumes.secrets

        return k8s_object.ListAsDictionaryWrapper(
            self._m,
            self._item_class,
            key_field=self._key_field,
            value_field=self._value_field,
            filter_func=_FilterSecretMounts)
Beispiel #12
0
    def config_maps(self):
        """Mutable dict-like object for vars with a config map source type."""
        def _FilterConfigMapEnvVars(env_var):
            return (env_var.valueFrom is not None
                    and env_var.valueFrom.configMapKeyRef is not None)

        return k8s_object.ListAsDictionaryWrapper(
            self._env_vars,
            self._env_var_class,
            value_field='valueFrom',
            filter_func=_FilterConfigMapEnvVars)
Beispiel #13
0
    def secrets(self):
        """Mutable dict-like object for vars with a secret source type."""
        def _FilterSecretEnvVars(env_var):
            return (env_var.valueFrom is not None
                    and env_var.valueFrom.secretKeyRef is not None)

        return k8s_object.ListAsDictionaryWrapper(
            self._env_vars,
            self._env_var_class,
            value_field='valueFrom',
            filter_func=_FilterSecretEnvVars)
    def build_template_arguments(self):
        """Returns a mutable, dict-like object to manage build template args.

    The returned object can be used like a dictionary, and any modifications to
    the returned object (i.e. setting and deleting keys) modify the underlying
    nested build template arguments fields.
    """
        self._AssertSupportsBuild()

        def create():
            self._EnsureBuild()
            return self._m.spec.build.template.arguments

        if self._m.spec.build and self._m.spec.build.template:
            return k8s_object.ListAsDictionaryWrapper(
                self._m.spec.build.template.arguments,
                self._messages.ArgumentSpec)
        else:
            return k8s_object.ListAsDictionaryWrapper(
                k8s_object.LazyListWrapper(create),
                self._messages.ArgumentSpec)
Beispiel #15
0
    def volume_mounts(self):
        """Returns a mutable, dict-like object to manage volume mounts.

    The returned object can be used like a dictionary, and any modifications to
    the returned object (i.e. setting and deleting keys) modify the underlying
    nested volume mounts.
    """
        if self.container:
            return k8s_object.ListAsDictionaryWrapper(
                self.container.volumeMounts,
                functools.partial(self._messages.VolumeMount, readOnly=True),
                key_field='mountPath',
                value_field='name')
Beispiel #16
0
    def literals(self):
        """Mutable dict-like object for env vars with a string literal.

    Note that if neither value nor valueFrom is specified, the list entry will
    be treated as a literal empty string.

    Returns:
      A mutable, dict-like object for managing string literal env vars.
    """
        return k8s_object.ListAsDictionaryWrapper(
            self._env_vars,
            self._env_var_class,
            filter_func=lambda env_var: env_var.valueFrom is None)
Beispiel #17
0
 def testListAsDictionaryWrapperSetObj(self):
     wrapped_msgs = k8s_object.ListAsDictionaryWrapper(
         self.messages, FakeMessage)
     wrapped_msgs['m0'] = -1
     wrapped_msgs['m5'] = 5
     self.assertDictEqual(
         {
             'm0': -1,
             'm1': 1,
             'm2': 2,
             'm3': 3,
             'm4': 4,
             'm5': 5,
         }, dict(wrapped_msgs))
Beispiel #18
0
    def testListAsDictionaryWrapperSetFailsIfBadOverwrite(self):
        """Overwriting should fail if existing message is not wrapped.

    If there's an existing message with the same unique key field, but is not
    included in the wrapped dict due to the filter func, overwrite should fail.
    """
        def _FilterFunc(obj):
            return obj.value > 2

        wrapped_msgs = k8s_object.ListAsDictionaryWrapper(
            self.messages, FakeMessage, filter_func=_FilterFunc)
        wrapped_msgs['m3'] = -3  # succeeds because included by filter
        with self.assertRaises(KeyError):
            wrapped_msgs['m0'] = -1
Beispiel #19
0
    def ce_overrides(self):
        """The CloudEvents Overrides Extensions map.

    This property is a dict-like object for managed CE override extensions.
    These key-value pairs will be added to the Extensions section of all
    CloudEvents produced by this source.

    Returns:
      A dict-like object for managing CE override extensions.
    """
        if self._m.spec.ceOverrides is None:
            self._m.spec.ceOverrides = self._messages.CloudEventOverrides(
                extensions=self._messages.CloudEventOverrides.ExtensionsValue(
                ))
        return k8s_object.ListAsDictionaryWrapper(
            self._m.spec.ceOverrides.extensions.additionalProperties,
            self._messages.CloudEventOverrides.ExtensionsValue.
            AdditionalProperty,
            key_field='key')
Beispiel #20
0
 def data(self):
     return k8s_object.ListAsDictionaryWrapper(
         self._m.data.additionalProperties,
         self._messages.Secret.DataValue.AdditionalProperty,
         key_field='key',
         value_field='value')
Beispiel #21
0
 def literals(self):
     """Mutable dict-like object for env vars with a string literal."""
     return k8s_object.ListAsDictionaryWrapper(
         self._env_vars,
         self._env_var_class,
         filter_func=lambda env_var: env_var.value is not None)
 def filter_attributes(self):
     return k8s_object.ListAsDictionaryWrapper(
         self._m.spec.filter.attributes.additionalProperties,
         self._messages.TriggerFilter.AttributesValue.AdditionalProperty,
         key_field='key',
         value_field='value')