...

Source file src/github.com/chaos-mesh/chaos-mesh/pkg/workflow/task/pod.go

Documentation: github.com/chaos-mesh/chaos-mesh/pkg/workflow/task

     1  // Copyright 2021 Chaos Mesh Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  // http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  //
    15  
    16  package task
    17  
    18  import (
    19  	corev1 "k8s.io/api/core/v1"
    20  
    21  	"github.com/chaos-mesh/chaos-mesh/api/v1alpha1"
    22  )
    23  
    24  const (
    25  	PodMetadataVolumeName            = "podmetadata"
    26  	PodMetadataAnnotationsVolumePath = ""
    27  	PodMetadataMountPath             = "/var/run/chaos-mesh/"
    28  )
    29  
    30  func SpawnPodForTask(task v1alpha1.Task) (corev1.PodSpec, error) {
    31  	deepCopiedContainer := task.Container.DeepCopy()
    32  	if len(deepCopiedContainer.Resources.Limits) == 0 {
    33  		deepCopiedContainer.Resources.Limits.Cpu().SetMilli(1000)
    34  		deepCopiedContainer.Resources.Limits.Memory().Set(1000)
    35  	}
    36  	result := corev1.PodSpec{
    37  		RestartPolicy: corev1.RestartPolicyNever,
    38  		Volumes:       attachVolumes(task),
    39  		Containers: []corev1.Container{
    40  			*deepCopiedContainer,
    41  		},
    42  	}
    43  	return result, nil
    44  }
    45  
    46  func attachVolumes(task v1alpha1.Task) []corev1.Volume {
    47  	var result []corev1.Volume
    48  
    49  	// TODO: downwards API and configmaps
    50  
    51  	result = append(result, task.Volumes...)
    52  	return result
    53  }
    54