Skip to content

Commit

Permalink
Add HasServiceTemplate & GetServiceTemplate helpers (#649)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored Nov 11, 2020
1 parent 25e0e4a commit 421d760
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions apis/kubedb/v1alpha2/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
appslister "k8s.io/client-go/listers/apps/v1"
apps_util "kmodules.xyz/client-go/apps/v1"
ofst "kmodules.xyz/offshoot-api/api/v1"
)

func checkReplicas(lister appslister.StatefulSetNamespaceLister, selector labels.Selector, expectedItems int) (bool, string, error) {
Expand All @@ -37,3 +38,25 @@ func checkReplicas(lister appslister.StatefulSetNamespaceLister, selector labels
ready, msg := apps_util.StatefulSetsAreReady(items)
return ready, msg, nil
}

// HasServiceTemplate returns "true" if the desired serviceTemplate provided in "aliaS" is present in the serviceTemplate list.
// Otherwise, it returns "false".
func HasServiceTemplate(templates []NamedServiceTemplateSpec, alias ServiceAlias) bool {
for i := range templates {
if templates[i].Alias == alias {
return true
}
}
return false
}

// GetServiceTemplate returns a pointer to the desired serviceTemplate referred by "aliaS". Otherwise, it returns nil.
func GetServiceTemplate(templates []NamedServiceTemplateSpec, alias ServiceAlias) ofst.ServiceTemplateSpec {
for i := range templates {
c := templates[i]
if c.Alias == alias {
return c.ServiceTemplate
}
}
return ofst.ServiceTemplateSpec{}
}

0 comments on commit 421d760

Please sign in to comment.