github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/tiltfile/k8s/readiness.go (about)

     1  package k8s
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"go.starlark.net/starlark"
     7  
     8  	"github.com/tilt-dev/tilt/internal/tiltfile/value"
     9  	"github.com/tilt-dev/tilt/pkg/model"
    10  )
    11  
    12  // Deserializing pod readiness from starlark values.
    13  type PodReadinessMode struct {
    14  	Value model.PodReadinessMode
    15  }
    16  
    17  func (m *PodReadinessMode) Unpack(v starlark.Value) error {
    18  	s, ok := value.AsString(v)
    19  	if !ok {
    20  		return fmt.Errorf("Must be a string. Got: %s", v.Type())
    21  	}
    22  
    23  	for _, mode := range []model.PodReadinessMode{
    24  		model.PodReadinessIgnore,
    25  		model.PodReadinessWait,
    26  		model.PodReadinessSucceeded,
    27  		model.PodReadinessNone,
    28  	} {
    29  		if s == string(mode) {
    30  			m.Value = mode
    31  			return nil
    32  		}
    33  	}
    34  
    35  	return fmt.Errorf("Invalid value. Allowed: {%s, %s}. Got: %s", model.PodReadinessIgnore, model.PodReadinessWait, s)
    36  }