github.com/jenkins-x/jx/v2@v2.1.155/pkg/kube/envrolebindings.go (about)

     1  package kube
     2  
     3  import (
     4  	v1 "github.com/jenkins-x/jx-api/pkg/apis/jenkins.io/v1"
     5  	"github.com/jenkins-x/jx/v2/pkg/util"
     6  )
     7  
     8  // EnvironmentMatches returns true if the environment matches the given filter
     9  func EnvironmentMatches(env *v1.Environment, filter *v1.EnvironmentFilter) bool {
    10  	kind := filter.Kind
    11  	if string(kind) != "" {
    12  		if env.Spec.Kind != kind {
    13  			return false
    14  		}
    15  	}
    16  	includes := filter.Includes
    17  	excludes := filter.Excludes
    18  	return util.StringMatchesAny(env.Name, includes, excludes)
    19  }
    20  
    21  // EnvironmentMatchesAny returns true if the list of filters is empty or one of the filters matches
    22  // the given environment
    23  func EnvironmentMatchesAny(env *v1.Environment, filters []v1.EnvironmentFilter) bool {
    24  	for _, f := range filters {
    25  		filter := f
    26  		if EnvironmentMatches(env, &filter) {
    27  			return true
    28  		}
    29  	}
    30  	return len(filters) == 0
    31  }