Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a file to specify the chronicle artifact prefix #217

Merged
merged 2 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions pkg/chronicle/chronicle_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

type PushParams struct {
ProfilePath string
ArtifactPath string
ArtifactFile string
Frequency time.Duration
EnvDir string
Command []string
Expand Down Expand Up @@ -85,8 +85,9 @@ func push(ctx context.Context, p PushParams, ord int) error {
return err
}
}
ap, err := readArtifactPathFile(p.ArtifactFile)
log.Debugf("Pushing output from Command %d: %v. Environment: %v", ord, p.Command, env)
return pushWithEnv(ctx, p.Command, p.ArtifactPath, ord, prof, env)
return pushWithEnv(ctx, p.Command, ap, ord, prof, env)
}

func pushWithEnv(ctx context.Context, c []string, suffix string, ord int, prof param.Profile, env []string) error {
Expand Down Expand Up @@ -121,12 +122,17 @@ func pushWithEnv(ctx context.Context, c []string, suffix string, ord int, prof p
return nil
}

func readArtifactPathFile(path string) (string, error) {
buf, err := ioutil.ReadFile(path)
t := strings.TrimSuffix(string(buf), "\n")
return t, errors.Wrap(err, "Could not read artifact path file")
}

func readProfile(path string) (p param.Profile, ok bool, err error) {
var buf []byte
buf, err = ioutil.ReadFile(path)
switch {
case os.IsNotExist(err):
ok = true
err = nil
return
case err != nil:
Expand Down
7 changes: 6 additions & 1 deletion pkg/chronicle/chronicle_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package chronicle

import (
"context"
"io/ioutil"
"os"
"path/filepath"

. "gopkg.in/check.v1"
Expand All @@ -28,9 +30,12 @@ func (s *ChroniclePushSuite) TestPush(c *C) {
err := writeProfile(pp, prof)
c.Assert(err, IsNil)

a := filepath.Join(c.MkDir(), "artifact")
err = ioutil.WriteFile(a, []byte(rand.String(10)), os.ModePerm)
c.Assert(err, IsNil)
p := PushParams{
ProfilePath: pp,
ArtifactPath: rand.String(10),
ArtifactFile: a,
Command: []string{"echo hello"},
}
ctx := context.Background()
Expand Down
8 changes: 6 additions & 2 deletions pkg/chronicle/chronicle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -42,9 +43,12 @@ func (s *ChronicleSuite) TestPushPull(c *C) {
err := writeProfile(pp, s.profile)
c.Assert(err, IsNil)

a := filepath.Join(c.MkDir(), "artifact")
err = ioutil.WriteFile(a, []byte(rand.String(10)), os.ModePerm)
c.Assert(err, IsNil)
p := PushParams{
ProfilePath: pp,
ArtifactPath: rand.String(10),
ArtifactFile: a,
}
ctx := context.Background()

Expand All @@ -56,7 +60,7 @@ func (s *ChronicleSuite) TestPushPull(c *C) {

// Pull and check that we still get i
buf := bytes.NewBuffer(nil)
err = Pull(ctx, buf, s.profile, p.ArtifactPath)
err = Pull(ctx, buf, s.profile, p.ArtifactFile)
c.Assert(err, IsNil)
str, err := ioutil.ReadAll(buf)
c.Assert(err, IsNil)
Expand Down
5 changes: 3 additions & 2 deletions pkg/kando/chronicle_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ func newChroniclePushCommand() *cobra.Command {
}
cmd.PersistentFlags().StringVarP(&params.ProfilePath, profilePathFlagName, "p", "", "Path to a Profile as a JSON string (required)")
cmd.MarkPersistentFlagRequired(profilePathFlagName)
cmd.PersistentFlags().StringVarP(&params.ArtifactPath, artifactPathFlagName, "s", "", "Specify a path suffix (optional)")
cmd.PersistentFlags().StringVarP(&params.EnvDir, envDirFlagName, "e", "", "Get environment variables from a (optional)")
cmd.PersistentFlags().StringVarP(&params.ArtifactFile, artifactPathFlagName, "s", "", "Specify a file that contains an object store suffix (optional)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] Remove optional

tdmanv marked this conversation as resolved.
Show resolved Hide resolved
cmd.MarkPersistentFlagRequired(artifactPathFlagName)
cmd.PersistentFlags().StringVarP(&params.EnvDir, envDirFlagName, "e", "", "Get environment variables from a envdir style directory(optional)")
cmd.PersistentFlags().DurationVarP(&params.Frequency, frequencyFlagName, "f", time.Minute, "The Frequency to push to object storage ")
return cmd
}