github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/pkg/treelabels/api.go (about)

     1  package treelabels
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/caos/orbos/pkg/labels"
     8  	"github.com/caos/orbos/pkg/tree"
     9  )
    10  
    11  func MustForAPI(tree *tree.Tree, operator *labels.Operator) *labels.API {
    12  	if tree == nil ||
    13  		tree.Common == nil ||
    14  		tree.Common.Kind == "" ||
    15  		strings.Count(tree.Common.Kind, "/") != 1 ||
    16  		tree.Common.Version() == "" {
    17  		panic(fmt.Errorf("invalid tree: %+v", tree))
    18  	}
    19  
    20  	return labels.MustForAPI(operator, strings.Split(tree.Common.Kind, "/")[1], tree.Common.Version())
    21  }