Ejemplo n.º 1
0
 def patch_namespaced_daemonset(self, name, image, namespace="default"):
     """Scale deployment using name in namespace to replicas"""
     # Configureate Pod template container
     container = client.V1Container(name=name)
     # Create and configurate a spec section
     template = client.V1PodTemplateSpec(
         metadata=client.V1ObjectMeta(labels={"app": name}),
         spec=client.V1PodSpec(containers=[container]))
     # Create the specification of DaemonSet
     spec = client.V1DaemonSetSpec(template=template,
                                   selector={'matchLabels': {
                                       'app': name
                                   }})
     # Instantiate the DaemonSet object
     daemonset = client.V1DaemonSet(api_version="apps/v1",
                                    kind="DaemonSet",
                                    metadata=client.V1ObjectMeta(name=name),
                                    spec=spec)
     daemonset.spec.template.spec.containers[0].image = image
     try:
         self.apps_cli.patch_namespaced_daemon_set(name, namespace,
                                                   daemonset)
         logger.info(
             'Image of daemonset {} in namespace {} has been updated to {}'.
             format(name, namespace, image))
         return
     except client.rest.ApiException as e:
         if e.status == 404 or not e.status:
             logger.info('Daemonset {} in namespace {} is not found'.format(
                 name, namespace))
             return
         logger.exception(e)
         return False
Ejemplo n.º 2
0
def simple_daemonset():
    """Return the Kubernetes config matching the simple-daemonset.yaml manifest."""
    return client.V1DaemonSet(
        api_version='apps/v1',
        kind='DaemonSet',
        metadata=client.V1ObjectMeta(name='canal-daemonset',
                                     labels={'app': 'canal'}),
        spec=client.V1DaemonSetSpec(
            selector=client.V1LabelSelector(match_labels={'app': 'canal'}),
            template=client.V1PodTemplateSpec(
                metadata=client.V1ObjectMeta(labels={'app': 'canal'}),
                spec=client.V1PodSpec(containers=[
                    client.V1Container(
                        name='canal',
                        image='canal:3.7.2',
                        ports=[client.V1ContainerPort(container_port=9099)])
                ]))))
Ejemplo n.º 3
0
def simple_daemonset():
    """Return the Kubernetes config matching the simple-daemonset.yaml manifest."""
    return client.V1DaemonSet(
        api_version="apps/v1",
        kind="DaemonSet",
        metadata=client.V1ObjectMeta(name="canal-daemonset",
                                     labels={"app": "canal"}),
        spec=client.V1DaemonSetSpec(
            selector=client.V1LabelSelector(match_labels={"app": "canal"}),
            template=client.V1PodTemplateSpec(
                metadata=client.V1ObjectMeta(labels={"app": "canal"}),
                spec=client.V1PodSpec(containers=[
                    client.V1Container(
                        name="canal",
                        image="canal:3.7.2",
                        ports=[client.V1ContainerPort(container_port=9099)],
                    )
                ]),
            ),
        ),
    )
Ejemplo n.º 4
0
def create_daemon_set_object():
    container = client.V1Container(
        name="ds-redis",
        image="redis",
        image_pull_policy="IfNotPresent",
        ports=[client.V1ContainerPort(container_port=6379)],
    )
    # Template
    template = client.V1PodTemplateSpec(
        metadata=client.V1ObjectMeta(labels={"app": "redis"}),
        spec=client.V1PodSpec(containers=[container]))
    # Spec
    spec = client.V1DaemonSetSpec(
        selector=client.V1LabelSelector(match_labels={"app": "redis"}),
        template=template)
    # DaemonSet
    daemonset = client.V1DaemonSet(
        api_version="apps/v1",
        kind="DaemonSet",
        metadata=client.V1ObjectMeta(name="daemonset-redis"),
        spec=spec)

    return daemonset
Ejemplo n.º 5
0
    def create_daemon_set_object(self):
        container = client.V1Container(
            name=self.container_name,
            args=self.args,
            image=self.image,
            image_pull_policy='IfNotPresent',
            ports=[client.V1ContainerPort(container_port=8080)],
            resources={"limits": {
                "cpu": "1",
                "memory": "512Mi"
            }},
            termination_message_policy='File',
            termination_message_path='/dev/termination-log',
            security_context={
                "allowPrivilegeEscalation": False,
                "capabilities": {},
                "privileged": False,
                "readOnlyRootFilesystem": False,
                "runAsNonRoot": False
            })

        template = client.V1PodTemplateSpec(
            metadata=client.V1ObjectMeta(annotations=self.annotations),
            spec=client.V1PodSpec(containers=[container]))

        # min_ready_seconds=None, revision_history_limit=None, selector=None, template=None, template_generation=None, update_strategy=None
        spec = client.V1DaemonSetSpec(revision_history_limit=3,
                                      template=template)

        daemon_set = client.V1DaemonSet(api_version='apps/v1',
                                        kind='DaemonSet',
                                        metadata=client.V1ObjectMeta(
                                            labels={},
                                            name=self.daemon_set_name,
                                            namespace=self.namespace),
                                        spec=spec)
        return daemon_set
Ejemplo n.º 6
0
 def _daemon_set(self):
     return client.V1DaemonSet(
         api_version='apps/v1',
         kind='DaemonSet',
         metadata=metadata(
             name=self.name,
             namespace=self.namespace,
         ),
         spec=client.V1DaemonSetSpec(
             selector=client.V1LabelSelector(
                 match_labels=self.labels
             ),
             template=client.V1PodTemplateSpec(
                 metadata=metadata(name=self.name),
                 spec=client.V1PodSpec(
                     service_account_name=self.name,
                     termination_grace_period_seconds=60,
                     containers=[
                         client.V1Container(
                             name=self.name,
                             image=self.image,
                             resources=client.V1ResourceRequirements(
                                 limits=dict({
                                     'cpu': '200m',
                                     'memory': '200Mi',
                                 }),
                                 requests=dict({
                                     'cpu': '200m',
                                     'memory': '200Mi',
                                 })
                             ),
                             env=[
                                 client.V1EnvVar(
                                     name='HOST_IP',
                                     value_from=client.V1EnvVarSource(
                                         field_ref=client.V1ObjectFieldSelector(
                                             field_path='status.hostIP',
                                         )
                                     ),
                                 ),
                                 client.V1EnvVar(
                                     name='HOST_NAME',
                                     value_from=client.V1EnvVarSource(
                                         field_ref=client.V1ObjectFieldSelector(
                                             field_path='spec.nodeName',
                                         )
                                     ),
                                 ),
                                 client.V1EnvVar(
                                     name='K8S_NAMESPACE',
                                     value_from=client.V1EnvVarSource(
                                         field_ref=client.V1ObjectFieldSelector(
                                             field_path='metadata.namespace',
                                         )
                                     ),
                                 ),
                                 client.V1EnvVar(
                                     name='CI_VERSION',
                                     value='k8s/1.1.1',
                                 ),
                                ],
                             volume_mounts=[
                                 client.V1VolumeMount(
                                     name='cwagentconfig',
                                     mount_path='/etc/cwagentconfig',
                                 ),
                                 client.V1VolumeMount(
                                     name='rootfs',
                                     mount_path='/rootfs',
                                     read_only='true',
                                 ),
                                 client.V1VolumeMount(
                                     name='dockersock',
                                     mount_path='/var/run/docker.sock',
                                     read_only='true',
                                 ),
                                 client.V1VolumeMount(
                                     name='varlibdocker',
                                     mount_path='/var/lib/docker',
                                     read_only='true',
                                 ),
                                 client.V1VolumeMount(
                                     name='sys',
                                     mount_path='/sys',
                                     read_only='true',
                                 ),
                                 client.V1VolumeMount(
                                     name='devdisk',
                                     mount_path='/dev/disk',
                                     read_only='true',
                                 ),
                             ]
                         )
                     ],
                     volumes=[
                         client.V1Volume(
                             name='cwagentconfig',
                             config_map='cwagentconfig',
                         ),
                         client.V1Volume(
                             name='rootfs',
                             host_path='/',
                         ),
                         client.V1Volume(
                             name='dockersock',
                             host_path='/var/run/docker.sock',
                         ),
                         client.V1Volume(
                             name='varlibdocker',
                             host_path='/var/lib/docker',
                         ),
                         client.V1Volume(
                             name='sys',
                             host_path='/sys',
                         ),
                         client.V1Volume(
                             name='devdisk',
                             host_path='/dev/disk/',
                         ),
                     ]
                 )
             )
         )
     )