Skip to content

Commit

Permalink
Support inline artifacts.
Browse files Browse the repository at this point in the history
Artifacts can now be inline with the sensor yaml. See ./examples/inline-sensor.yaml
as an example.

Refs argoproj#41
  • Loading branch information
shrinandj committed Jul 21, 2018
1 parent 9ebb7fb commit a6f4144
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 194 deletions.
35 changes: 35 additions & 0 deletions examples/inline-sensor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: argoproj.io/v1alpha1
kind: Sensor
metadata:
name: inline-example
labels:
sensors.argoproj.io/controller-instanceid: axis
spec:
signals:
- name: time
calendar:
interval: 10s
triggers:
- name: inline-workflow-trigger
resource:
namespace: default
group: argoproj.io
version: v1alpha1
kind: Workflow
artifactLocation:
inline: |
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: hello-world-
spec:
entrypoint: whalesay
templates:
-
container:
args:
- "hello world"
command:
- cowsay
image: "docker/whalesay:latest"
name: whalesay
411 changes: 224 additions & 187 deletions pkg/apis/sensor/v1alpha1/generated.pb.go

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pkg/apis/sensor/v1alpha1/generated.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/apis/sensor/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ type URI struct {

// ArtifactLocation describes the location for an external artifact
type ArtifactLocation struct {
S3 *S3Artifact `json:"s3,omitempty" protobuf:"bytes,1,opt,name=s3"`
S3 *S3Artifact `json:"s3,omitempty" protobuf:"bytes,1,opt,name=s3"`
Inline string `json:"inline,omitempty" protobuf:"bytes,3,opt,name=inline"`
}

// S3Artifact contains information about an artifact in S3
Expand Down
4 changes: 2 additions & 2 deletions store/creds.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func GetCredentials(kubeClient kubernetes.Interface, namespace string, art *v1al
secretKey: secretKey,
}, nil
}
// this should never happen
return nil, fmt.Errorf("artifact is not an S3 artifact")

return nil, nil
}

// getSecrets retrieves the secret value from the secret in namespace with name and key
Expand Down
9 changes: 5 additions & 4 deletions store/creds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ func TestGetCredentials(t *testing.T) {
_, err := fakeClient.CoreV1().Secrets("testing").Create(mySecretCredentials)
assert.Nil(t, err)

// fail for an unknown artifact type
// creds should be nil for unknown artifact type
unknownArtifact := &v1alpha1.ArtifactLocation{}
_, err = GetCredentials(fakeClient, "testing", unknownArtifact)
assert.NotNil(t, err)
creds, err := GetCredentials(fakeClient, "testing", unknownArtifact)
assert.Nil(t, creds)
assert.Nil(t, err)

// succeed for S3 artifact type
s3Artifact := &v1alpha1.ArtifactLocation{
Expand All @@ -60,7 +61,7 @@ func TestGetCredentials(t *testing.T) {
},
},
}
creds, err := GetCredentials(fakeClient, "testing", s3Artifact)
creds, err = GetCredentials(fakeClient, "testing", s3Artifact)
assert.Nil(t, err)
assert.NotNil(t, creds)
assert.Equal(t, "token", creds.accessKey)
Expand Down
16 changes: 16 additions & 0 deletions store/inline.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package store

// InlineReader implements the ArtifactReader interface for inlined artifacts
type InlineReader struct {
inlineArtifact string
}

// NewInlineReader creates a new ArtifactReader for inline
func NewInlineReader(inlineArtifact string) (ArtifactReader, error) {
// TODO(shri): Add logging here
return &InlineReader{inlineArtifact}, nil
}

func (reader *InlineReader) Read() ([]byte, error) {
return []byte(reader.inlineArtifact), nil
}
18 changes: 18 additions & 0 deletions store/inline_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package store

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestInlineReader(t *testing.T) {
myStr := "myStr"
inlineReader, err := NewInlineReader(myStr)
assert.NotNil(t, inlineReader)
assert.Nil(t, err)
data, err := inlineReader.Read()
assert.NotNil(t, data)
assert.Nil(t, err)
assert.Equal(t, string(data), myStr)
}
2 changes: 2 additions & 0 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func FetchArtifact(reader ArtifactReader, gvk ss_v1alpha1.GroupVersionKind) (*un
func GetArtifactReader(loc *ss_v1alpha1.ArtifactLocation, creds *Credentials) (ArtifactReader, error) {
if loc.S3 != nil {
return NewS3Reader(loc.S3, creds)
} else if loc.Inline != "" {
return NewInlineReader(loc.Inline)
}
return nil, fmt.Errorf(fmt.Sprintf("unknown artifact location: %v", *loc))
}
Expand Down

0 comments on commit a6f4144

Please sign in to comment.