Skip to content
Snippets Groups Projects
Select Git revision
  • 6ddfd11f5a90ba5092c77ab1976a43d913b471a0
  • master default protected
  • v0.0.x
  • v0.0.31
  • v0.0.30
  • v0.0.29
  • v0.0.28
  • v0.0.28-rc1
  • v0.0.27
  • v0.0.26
  • v0.0.25
  • v0.0.24
  • v0.0.23
  • v0.0.22
  • v0.0.21
  • v0.0.20
  • v0.0.19
  • v0.0.18
  • v0.0.17
  • v0.0.16
  • v0.0.15
  • v0.0.14
  • v0.0.13
23 results

util.go

Blame
  • util.go 926 B
    package main
    
    import (
    	"encoding/json"
    	"fmt"
    	"io/ioutil"
    	"os"
    
    	v1 "k8s.io/api/core/v1"
    	"sigs.k8s.io/yaml"
    )
    
    func loadFile(filepath string) (string, error) {
    	f, err := os.Open(filepath)
    	if err != nil {
    		return "", err
    	}
    	defer f.Close()
    	helperPodYaml, err := ioutil.ReadAll(f)
    	if err != nil {
    		return "", err
    	}
    	return string(helperPodYaml), nil
    }
    
    func loadHelperPodFile(helperPodYaml string) (*v1.Pod, error) {
    	helperPodJSON, err := yaml.YAMLToJSON([]byte(helperPodYaml))
    	if err != nil {
    		return nil, fmt.Errorf("invalid YAMLToJSON the helper pod with helperPodYaml: %v", helperPodYaml)
    	}
    	p := v1.Pod{}
    	err = json.Unmarshal(helperPodJSON, &p)
    	if err != nil {
    		return nil, fmt.Errorf("invalid unmarshal the helper pod with helperPodJson: %v", string(helperPodJSON))
    	}
    	if len(p.Spec.Containers) == 0 {
    		return nil, fmt.Errorf("helper pod template does not specify any container")
    	}
    	return &p, nil
    }