Skip to content
Snippets Groups Projects
Select Git revision
  • 89cfb5f4c4e3030efc5087e9121ab840f6993ec0
  • master default protected
  • v1.14.7
  • v1.14.6
  • v1.14.5
  • v1.14.4
  • v1.14.3
  • v1.14.2
  • v1.14.1
  • v1.14.0
  • v1.13.2
  • v1.13.1
  • v1.13.0
  • v1.12.1
  • v1.12.0
  • v1.11.1
  • v1.11.0
  • v1.10.0
  • v1.9.2
  • v1.9.1
  • v1.9.0
  • v1.8.4
22 results

setup.py

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
    }