Skip to content

Commit

Permalink
model: move some functions for working with lists of targets to the m…
Browse files Browse the repository at this point in the history
…odel package (#1543)
  • Loading branch information
nicks authored Apr 26, 2019
1 parent 2bbb57c commit 9ce987d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 41 deletions.
37 changes: 0 additions & 37 deletions internal/engine/extractors.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,6 @@ func extractImageAndK8sTargets(specs []model.TargetSpec) (iTargets []model.Image
return iTargets, kTargets
}

// Check to see if we have k8s targets.
func extractK8sTargets(specs []model.TargetSpec) []model.K8sTarget {
kTargets := make([]model.K8sTarget, 0)
for _, spec := range specs {
t, ok := spec.(model.K8sTarget)
if !ok {
continue
}
kTargets = append(kTargets, t)
}
return kTargets
}

func extractImageTargets(specs []model.TargetSpec) []model.ImageTarget {
iTargets := make([]model.ImageTarget, 0)
for _, spec := range specs {
t, ok := spec.(model.ImageTarget)
if !ok {
continue
}
iTargets = append(iTargets, t)
}
return iTargets
}

func extractDockerComposeTargets(specs []model.TargetSpec) []model.DockerComposeTarget {
targets := make([]model.DockerComposeTarget, 0)
for _, spec := range specs {
t, ok := spec.(model.DockerComposeTarget)
if !ok {
continue
}
targets = append(targets, t)
}
return targets
}

// Extract image targets iff they can be updated in-place in a container.
func extractImageTargetsForLiveUpdates(specs []model.TargetSpec, stateSet store.BuildStateSet) ([]model.ImageTarget, error) {
iTargets := make([]model.ImageTarget, 0)
Expand Down
4 changes: 2 additions & 2 deletions internal/engine/local_container_build_and_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func (cbd *LocalContainerBuildAndDeployer) BuildAndDeploy(ctx context.Context, s
return store.BuildResultSet{}, SilentRedirectToNextBuilderf("Local container builder needs exactly one image target")
}

isDC := len(extractDockerComposeTargets(specs)) > 0
isK8s := len(extractK8sTargets(specs)) > 0
isDC := len(model.ExtractDockerComposeTargets(specs)) > 0
isK8s := len(model.ExtractK8sTargets(specs)) > 0
canLocalUpdate := isDC || (isK8s && cbd.env.IsLocalCluster())
if !canLocalUpdate {
return store.BuildResultSet{}, SilentRedirectToNextBuilderf("Local container builder needs docker-compose or k8s cluster w/ local updates")
Expand Down
2 changes: 1 addition & 1 deletion internal/engine/synclet_build_and_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (sbd *SyncletBuildAndDeployer) BuildAndDeploy(ctx context.Context, st store
}

iTarget := iTargets[0]
if !isImageDeployedToK8s(iTarget, extractK8sTargets(specs)) {
if !isImageDeployedToK8s(iTarget, model.ExtractK8sTargets(specs)) {
return store.BuildResultSet{}, SilentRedirectToNextBuilderf("Synclet container builder can only deploy to k8s")
}

Expand Down
2 changes: 1 addition & 1 deletion internal/engine/upper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (b *fakeBuildAndDeployer) BuildAndDeploy(ctx context.Context, st store.RSto
}

result := store.BuildResultSet{}
for _, iTarget := range extractImageTargets(specs) {
for _, iTarget := range model.ExtractImageTargets(specs) {
var deployTarget model.TargetSpec
if !call.dc().Empty() {
if isImageDeployedToDC(iTarget, call.dc()) {
Expand Down
37 changes: 37 additions & 0 deletions internal/model/extractors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package model

func ExtractK8sTargets(specs []TargetSpec) []K8sTarget {
kTargets := make([]K8sTarget, 0)
for _, spec := range specs {
t, ok := spec.(K8sTarget)
if !ok {
continue
}
kTargets = append(kTargets, t)
}
return kTargets
}

func ExtractImageTargets(specs []TargetSpec) []ImageTarget {
iTargets := make([]ImageTarget, 0)
for _, spec := range specs {
t, ok := spec.(ImageTarget)
if !ok {
continue
}
iTargets = append(iTargets, t)
}
return iTargets
}

func ExtractDockerComposeTargets(specs []TargetSpec) []DockerComposeTarget {
targets := make([]DockerComposeTarget, 0)
for _, spec := range specs {
t, ok := spec.(DockerComposeTarget)
if !ok {
continue
}
targets = append(targets, t)
}
return targets
}

0 comments on commit 9ce987d

Please sign in to comment.