Skip to content

Commit

Permalink
initial design ideas for source
Browse files Browse the repository at this point in the history
Signed-off-by: Shash Reddy <[email protected]>
  • Loading branch information
nader-ziada authored and Shash Reddy committed Sep 11, 2018
1 parent ef113e1 commit 5d61fc2
Show file tree
Hide file tree
Showing 9 changed files with 399 additions and 110 deletions.
43 changes: 28 additions & 15 deletions examples/pipelines/kritis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ spec:
- name: unit-test-kritis # 1. Run unit Tests
taskRef:
name: make
sourceBindings:
inputSourceBindings:
- inputName: workspace
sourceKey: kritis
params:
Expand All @@ -17,27 +17,25 @@ spec:
- name: push-kritis # 2. Build And Push Tests
taskRef:
name: build-push
sourceBindings:
- inputName: workspace
inputSourceBindings:
- name: workspace
sourceKey: kritis
artifactStoreBindings:
- storeName: registry
storeKey: stagingRegistry
builtImage: kritis # TODO Add Commit SHA
outputSourceBindings:
- name: registry
sourceKey: stagingRegistry
params:
- name: pathToDockerfile
value: deploy/Dockerfile
prevTasks: ['unit-test-kritis']
- name: deploy-test-env # 3. Finally Deploy to Test environment
taskRef:
name: deploy-with-helm
sourceBindings:
- inputName: workspace
inputSourceBindings:
- name: workspace
sourceKey: kritis
paramBindings: # Implicit dependency on buildPush task.
- inputName: testImage
taskName: buildPush
taskOutputName: builtImage
- name: registry
sourceKey: stagingRegistry
passedConstraints: [push-kritis]
params:
- name: pathToHelmCharts
value: kritis-charts
Expand All @@ -47,9 +45,24 @@ spec:
- name: integration-test # 4. Run Integration Tests in test cluster
taskRef:
name: integration-test-in-docker
sourceBindings:
- inputName: workspace
inputSourceBindings:
- name: workspace
sourceKey: kritis
params:
- name: testArgs
value: "-e REMOTE_INTEGRATION=true"
sources:
- name: kritis
type: git
params:
- name: url
value: https://github.com/grafeas/kritis
- name: branch
value: master
- name: stagingRegistry
type: image
params:
- name: buildImage
value: kritis


45 changes: 45 additions & 0 deletions pkg/apis/pipeline/v1beta1/git_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Copyright 2018 The Knative Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1

// GitSource is an endpoint from which to get data which is required
// by a Build/Task for context (e.g. a repo from which to build an image).
type GitSource struct {
Name string `json:"name"`
Type string `json:"type"`
URL string `json:"url"`
Branch string `json:"branch"`
Commit string `json:"commit,omitempty"`
ServiceAccount string `json:"serviceAccount,omitempty"`
}

func (s GitSource) getName() string {
return s.Name
}

func (s GitSource) getType() string {
return "git"
}

func (s GitSource) getVersion() string {
return s.Commit
}

func (s GitSource) getParams() []Param {
var result []Param
return result
}
43 changes: 43 additions & 0 deletions pkg/apis/pipeline/v1beta1/image_source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
Copyright 2018 The Knative Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1

// ImageSource defines an endpoint where artifacts can be stored, such as images.
type ImageSource struct {
Name string `json:"name"`
// TODO: maybe an enum, with values like 'registry', GCS bucket
Type string `json:"type"`
URL string `json:"url"`
Sha string `json:"sha"`
}

func (s ImageSource) getName() string {
return s.Name
}

func (s ImageSource) getType() string {
return "image"
}

func (s ImageSource) getVersion() string {
return s.Sha
}

func (s ImageSource) getParams() []Param {
var result []Param
return result
}
46 changes: 29 additions & 17 deletions pkg/apis/pipeline/v1beta1/pipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import (

// PipelineSpec defines the desired state of PipeLine.
type PipelineSpec struct {
Tasks []PipelineTask `json:"tasks"`
Tasks []PipelineTask `json:"tasks"`
Sources []PipelineSource `json:"sources"`
}

// PipelineStatus defines the observed state of Pipeline
Expand Down Expand Up @@ -50,12 +51,12 @@ type Pipeline struct {
// PipelineTask defines a task in a Pipeline, passing inputs from both
// PipelineParams and from the output of previous tasks.
type PipelineTask struct {
Name string `json:"name"`
TaskRef TaskRef `json:"taskRef"`
SourceBindings []SourceBinding `json:"sourceBindings,omitempty"`
ArtifactStoreBindings []ArtifactStoreBinding `json:"artifactStoreBindings,omitempty"`
Params []PipelineTaskParam `json:"params,omitempty"`
ParamBindings []PipelineTaskParamBinding `json:"paramBindings,omitempty"`
Name string `json:"name"`
TaskRef TaskRef `json:"taskRef"`
InputSourceBindings []SourceBinding `json:"inputSourceBindings,omitempty"`
OutputSourceBindings []SourceBinding `json:"outputSourceBindings,omitempty"`
Params []Param `json:"params,omitempty"`
ParamBindings []PipelineTaskParamBinding `json:"paramBindings,omitempty"`

NextTasks []string `json:"nextTasks,omitempty"`
PrevTasks []string `json:"prevTasks,omitempty"`
Expand All @@ -78,18 +79,11 @@ type PipelineTaskParam struct {
// as an input for a task.
type SourceBinding struct {
// InputName is the string the Task will use to identify this source in its inputs.
InputName string `json:"inputName"`
Name string `json:"name"`
// SourceKey is the string that the PipelineParams will use to identify this source.
SourceKey string `json:"sourceKey"`
}

// ArtifactStoreBinding is used to bind an ArtifactStore from a PipelineParams to
// artifacts that will be produced as output by a task.
type ArtifactStoreBinding struct {
// InputName is the string the Task will use to identify this source in its outputs.
StoreName string `json:"storeName"`
// StoreKey is the string that the PipelineParams will use to identify this artifact store.
StoreKey string `json:"storeKey"`
// PassedConstraints is the list of Task reference that the source has to pass through.
PassedConstraints []TaskRef `json:"passedConstraints,omitempty"`
}

// TaskRef can be used to refer to a specific instance of a task.
Expand All @@ -101,6 +95,24 @@ type TaskRef struct {
APIVersion string `json:"apiVersion,omitempty"`
}

// PipelineSource
type PipelineSource struct {
Name string `json:"name"`
Type string `json:"type"`
SourceRef SourceRef `json:"sourceRef"`
Params []Param `json:"params,omitempty"`
}

// SourceRef can be used to refer to a specific instance of a Source.
type SourceRef struct {
// Kind of the referent; More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds"
Kind string `json:"kind"`
// Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names
Name string `json:"name"`
// API version of the referent
APIVersion string `json:"apiVersion,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// PipelineList contains a list of Pipeline
Expand Down
29 changes: 8 additions & 21 deletions pkg/apis/pipeline/v1beta1/pipelineparams_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,16 @@ import (

// PipelineParamsSpec is the spec for a Pipeline resource
type PipelineParamsSpec struct {
ServiceAccount string `json:"serviceAccount"`
Sources []Source `json:"sources"`
ArtifactStores []ArtifactStore `json:"artifactStores"`
Results Results `json:"results"`
ServiceAccount string `json:"serviceAccount"`
Results Results `json:"results"`
}

// Source is an endpoint from which to get data which is required
// by a Build/Task for context (e.g. a repo from which to build an image).
type Source struct {
Name string `json:"name"`
Type string `json:"type"`
URL string `json:"url"`
Branch string `json:"branch"`
Commit string `json:"commit,omitempty"`
ServiceAccount string `json:"serviceAccount,omitempty"`
type Source interface {
getName() string
getType() string
getParams() []Param
getVersion() string
getPassingConstraints() []TaskRef
}

// PipelineParamsStatus defines the observed state of PipelineParams
Expand All @@ -58,14 +53,6 @@ type PipelineParams struct {
Status PipelineParamsStatus `json:"status,omitempty"`
}

// ArtifactStore defines an endpoint where artifacts can be stored, such as images.
type ArtifactStore struct {
Name string `json:"name"`
// TODO: maybe an enum, with values like 'registry', GCS bucket
Type string `json:"type"`
URL string `json:"url"`
}

// Results tells a pipeline where to persist the results of runnign the pipeline.
type Results struct {
// Runs is used to store the yaml/json of TaskRuns and PipelineRuns.
Expand Down
5 changes: 3 additions & 2 deletions pkg/apis/pipeline/v1beta1/pipelinerun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ type PipelineRunSpec struct {

// PipelineRunStatus defines the observed state of PipelineRun
type PipelineRunStatus struct {
TaskRuns []PipelineTaskRun `json:"taskRuns,omitempty"`
Conditions []PipelineRunCondition `json:"conditions"`
TaskRuns []PipelineTaskRun `json:"taskRuns,omitempty"`
SourceVersion []SourceVersion `json:"sourceVersion, omitempty"`
Conditions []PipelineRunCondition `json:"conditions"`
}

// +genclient
Expand Down
57 changes: 57 additions & 0 deletions pkg/apis/pipeline/v1beta1/sourceversion_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright 2018 The Knative Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// SourceVersionSpec defines the desired state of SourceVersion
type SourceVersionSpec struct {
SourceRef SourceRef `json:"sourceRef"`
Version string `json:"string"`
}

// SourceVersionStatus defines the observed state of TaskRun
type SourceVersionStatus struct {
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// SourceVersion is the Schema for the sourceversion API
// +k8s:openapi-gen=true
type SourceVersion struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec SourceVersionSpec `json:"spec,omitempty"`
Status SourceVersionStatus `json:"status,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// SourceVersionList contains a list of SourceVersion
type SourceVersionList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []SourceVersion `json:"items"`
}

func init() {
SchemeBuilder.Register(&SourceVersion{}, &SourceVersionList{})
}
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1beta1/taskrun_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ type TaskRunSpec struct {

// TaskRunInputs holds the input values that this task was invoked with.
type TaskRunInputs struct {
Sources []Source `json:"sources"`
Params []Param `json:"params,omitempty"`
Sources []SourceVersion `json:"sourcesVersion"`
Params []Param `json:"params,omitempty"`
}

// Trigger defines a webhook style trigger to start a TaskRun
Expand Down
Loading

0 comments on commit 5d61fc2

Please sign in to comment.