Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1510 from weaveworks/2381-func
Browse files Browse the repository at this point in the history
event: Add IsKindExecute() method for ReleaseSpec
  • Loading branch information
lelenanam authored Nov 14, 2018
2 parents 74b0d18 + 30cbcab commit 490e40b
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"time"

"encoding/json"
"errors"

"github.com/pkg/errors"
"github.com/weaveworks/flux"
"github.com/weaveworks/flux/update"
)
Expand Down Expand Up @@ -257,6 +257,25 @@ type ReleaseSpec struct {
ReleaseContainersSpec *update.ReleaseContainersSpec
}

// IsKindExecute reports whether the release spec s has ReleaseImageSpec or ReleaseImageSpec with Kind execute
// or error if s has invalid Type
func (s ReleaseSpec) IsKindExecute() (bool, error) {
switch s.Type {
case ReleaseImageSpecType:
if s.ReleaseImageSpec != nil && s.ReleaseImageSpec.Kind == update.ReleaseKindExecute {
return true, nil
}
case ReleaseContainersSpecType:
if s.ReleaseContainersSpec != nil && s.ReleaseImageSpec.Kind == update.ReleaseKindExecute {
return true, nil
}

default:
return false, errors.Errorf("unknown release spec type %s", s.Type)
}
return false, nil
}

// UnmarshalJSON for old version of spec (update.ReleaseImageSpec) where Type is empty
func (s *ReleaseSpec) UnmarshalJSON(b []byte) error {
type T ReleaseSpec
Expand Down

0 comments on commit 490e40b

Please sign in to comment.