Skip to content

Commit

Permalink
Add "valid" condition to all resources
Browse files Browse the repository at this point in the history
All resources will be evaluated by their controllers after they are
created to determine if they are valid or not. This PR adds a "Valid"
condition to the status of all resoruces which can be used by the
controller to inform the user of this (otherwise I think we'd have to
implement this kind of validation via admission controllers? maybe
that's better?)

This would be used by the logic that will be implemented for validation
in #33 #32 #31 #29 #30.
  • Loading branch information
bobcatfish committed Sep 18, 2018
1 parent fddb0fa commit 0d73c63
Show file tree
Hide file tree
Showing 23 changed files with 281 additions and 114 deletions.
23 changes: 23 additions & 0 deletions config/crds/pipeline_v1beta1_pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,29 @@ spec:
- tasks
type: object
status:
properties:
conditions:
items:
properties:
lastTransitionTime:
format: date-time
type: string
message:
type: string
reason:
type: string
status:
type: string
type:
type: string
required:
- type
- status
- lastTransitionTime
type: object
type: array
required:
- conditions
type: object
type: object
version: v1beta1
Expand Down
23 changes: 23 additions & 0 deletions config/crds/pipeline_v1beta1_pipelineparams.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,29 @@ spec:
- results
type: object
status:
properties:
conditions:
items:
properties:
lastTransitionTime:
format: date-time
type: string
message:
type: string
reason:
type: string
status:
type: string
type:
type: string
required:
- type
- status
- lastTransitionTime
type: object
type: array
required:
- conditions
type: object
type: object
version: v1beta1
Expand Down
23 changes: 23 additions & 0 deletions config/crds/pipeline_v1beta1_task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,29 @@ spec:
- buildSpec
type: object
status:
properties:
conditions:
items:
properties:
lastTransitionTime:
format: date-time
type: string
message:
type: string
reason:
type: string
status:
type: string
type:
type: string
required:
- type
- status
- lastTransitionTime
type: object
type: array
required:
- conditions
type: object
type: object
version: v1beta1
Expand Down
7 changes: 7 additions & 0 deletions config/samples/pipeline_v1beta1_pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,10 @@ spec:
taskName: buildPush
taskOutputName: builtImage
prevTasks: ['integrationTest']
status:
conditions:
- type: Valid
status: "True"
lastTransitionTime: "2018-10-04T12:25:39Z"
reason: created
message: "Pipeline has been validated"
7 changes: 7 additions & 0 deletions config/samples/pipeline_v1beta1_pipelineparams.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ spec:
- name: 'prod'
type: 'gke'
endpoint: 'https://prod.gke.corp.com'
status:
conditions:
- type: Valid
status: "True"
lastTransitionTime: "2018-10-04T12:25:39Z"
reason: created
message: "PipelineParams have been validated"
7 changes: 6 additions & 1 deletion config/samples/pipeline_v1beta1_pipelinerun.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ status:
- taskRef:
name: test-wizzbang-task-run-sd8f8dfasdfasdfas
conditions:
- type: Valid
status: "True"
lastTransitionTime: "2018-10-04T12:25:39Z"
reason: created
message: "PipelineRun has been validated"
- type: Started
status: "True"
lastTransitionTime: "2018-10-04T12:25:39Z"
Expand All @@ -35,7 +40,7 @@ status:
status: "True"
lastTransitionTime: "2018-10-04T13:25:39Z"
reason: done
message: "Pipeline execution has finished"
message: "PipelineRun execution has finished"
- type: Successful
status: "False"
lastTransitionTime: "2018-10-04T13:25:39Z"
Expand Down
9 changes: 8 additions & 1 deletion config/samples/pipeline_v1beta1_task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ spec:
- name: DOCKERFILE
value: ${PATH_TO_DOCKERFILE}
- name: REGISTRY
value: ${REGISTRY}
value: ${REGISTRY}
status:
conditions:
- type: Valid
status: "True"
lastTransitionTime: "2018-10-04T12:25:39Z"
reason: created
message: "Task has been validated"
5 changes: 5 additions & 0 deletions config/samples/pipeline_v1beta1_taskrun.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ status:
logsURL: 'gcs://somebucket/results/tests/test-wizzbang-task-run-sd8f8dfasdfasdfas/test'
exitCode: 0
conditions:
- type: Valid
status: "True"
lastTransitionTime: "2018-10-04T12:25:39Z"
reason: created
message: "TaskRun has been validated"
- type: Started
status: "True"
lastTransitionTime: "2018-10-04T12:25:39Z"
Expand Down
7 changes: 7 additions & 0 deletions examples/build_task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,10 @@ spec:
value: ${pathToDockerFile}
- name: REGISTRY
value: ${registry}
status:
conditions:
- type: Valid
status: "True"
lastTransitionTime: "2018-10-04T12:25:39Z"
reason: created
message: "Task has been validated"
14 changes: 14 additions & 0 deletions examples/deploy_tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ spec:
- name: deploy
image: kubernetes-helm
args: ['deploy', '--path=${pathToHelmChart}', '--set image=${image}', '${helmArgs}']
status:
conditions:
- type: Valid
status: "True"
lastTransitionTime: "2018-10-04T12:25:39Z"
reason: created
message: "Task has been validated"

---
apiVersion: pipeline.knative.dev/v1beta1
Expand All @@ -45,3 +52,10 @@ spec:
- name: runKubectl
image: k8s-kubectl
args: ['--use-context', '${targetCluster}', '--namespace', '${targetCluster.namespace}', 'apply', '-c', '${pathToFiles}', '${kubectlArgs}']
status:
conditions:
- type: Valid
status: "True"
lastTransitionTime: "2018-10-04T12:25:39Z"
reason: created
message: "Task has been validated"
5 changes: 5 additions & 0 deletions examples/invocations/kritis-pipeline-run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ status:
- taskRef:
name: unit-test-kritis-12321312984
conditions:
- type: Valid
status: "True"
lastTransitionTime: "2018-10-04T12:25:39Z"
reason: created
message: "PipelineRun has been validated"
- type: Started
status: "True"
lastTransitionTime: "2018-10-04T12:25:39Z"
Expand Down
5 changes: 5 additions & 0 deletions examples/invocations/run-kritis-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ status:
logsURL: 'gcs://somebucket/results/tests/unit-test-kritis-feature-x/make'
exitCode: 0
conditions:
- type: Valid
status: "True"
lastTransitionTime: "2018-10-04T12:25:39Z"
reason: created
message: "TaskRun has been validated"
- type: Started
status: "True"
lastTransitionTime: "2018-10-04T12:25:39Z"
Expand Down
7 changes: 7 additions & 0 deletions examples/pipelineparams.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,10 @@ spec:
type: 'gcs'
url: 'gcs://somebucket/results/tests'
token: 'todo'
status:
conditions:
- type: Valid
status: "True"
lastTransitionTime: "2018-10-04T12:25:39Z"
reason: created
message: "PipelineParams have been validated"
7 changes: 7 additions & 0 deletions examples/pipelines/guestbook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,10 @@ spec:
prevTasks:
- int-test-osx
- int-test-linux
status:
conditions:
- type: Valid
status: "True"
lastTransitionTime: "2018-10-04T12:25:39Z"
reason: created
message: "Pipeline has been validated"
7 changes: 7 additions & 0 deletions examples/pipelines/kritis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,10 @@ spec:
params:
- name: testArgs
value: "-e REMOTE_INTEGRATION=true"
status:
conditions:
- type: Valid
status: "True"
lastTransitionTime: "2018-10-04T12:25:39Z"
reason: created
message: "Pipeline has been validated"
15 changes: 14 additions & 1 deletion examples/test_tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ spec:
- name: runMake
image: ubuntu
args: ['make', '${makeTarget}']
status:
conditions:
- type: Valid
status: "True"
lastTransitionTime: "2018-10-04T12:25:39Z"
reason: created
message: "Task has been validated"

---
apiVersion: pipeline.knative.dev/v1beta1
Expand Down Expand Up @@ -56,4 +63,10 @@ spec:
- name: dockerSocket
source: /var/run/docker.sock
destination: /var/run/docker.sock

status:
conditions:
- type: Valid
status: "True"
lastTransitionTime: "2018-10-04T12:25:39Z"
reason: created
message: "Task has been validated"
55 changes: 55 additions & 0 deletions pkg/apis/pipeline/v1beta1/condition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
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 (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ConditionType indicates the status of the execution of the PipelineRun.
type ConditionType string

const (
// ConditionTypeValid indicates whether or not the created
// Resource was found to be valid by the Controller.
ConditionTypeValid ConditionType = "Valid"

// ConditionTypeStarted indicates whether or not the Run
// has started actually executing - applies only to Runs.
ConditionTypeStarted ConditionType = "Started"

// ConditionTypeCompleted indicates whether or not the Run
// has finished executing - applies only to Runs.
ConditionTypeCompleted ConditionType = "Completed"

// ConditionTypeSucceeded indicates whether or not the Run
// was successful - applies only to Runs.
ConditionTypeSucceeded ConditionType = "Successful"
)

// Condition holds a Condition that the Resource has entered into after being created.
type Condition struct {
Type ConditionType `json:"type"`

Status corev1.ConditionStatus `json:"status"`

LastTransitionTime metav1.Time `json:"lastTransitionTime"`

Reason string `json:"reason,omitempty"`
Message string `json:"message,omitempty"`
}
7 changes: 4 additions & 3 deletions pkg/apis/pipeline/v1beta1/pipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ type PipelineSpec struct {
Tasks []PipelineTask `json:"tasks"`
}

// PipelineStatus defines the observed state of Pipeline
// PipelineStatus defines the observed state of Pipeline.
// The controller will update the Conditions to indicate if the created
// resource is valid.
type PipelineStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Conditions []Condition `json:"conditions"`
}

// +genclient
Expand Down
7 changes: 4 additions & 3 deletions pkg/apis/pipeline/v1beta1/pipelineparams_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ type Source struct {
ServiceAccount string `json:"serviceAccount,omitempty"`
}

// PipelineParamsStatus defines the observed state of PipelineParams
// PipelineParamsStatus defines the observed state of PipelineParams.
// The controller will update the Conditions to indicate if the created
// resource is valid.
type PipelineParamsStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Conditions []Condition `json:"conditions"`
}

// +genclient
Expand Down
Loading

0 comments on commit 0d73c63

Please sign in to comment.