diff --git a/Gopkg.lock b/Gopkg.lock index 1f280e5d..d308d8c0 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -2,143 +2,112 @@ [[projects]] - digest = "1:218ae0d3f01ab221e2a62493a88e72189fb4941b22f60984277c22f664d34c46" name = "cloud.google.com/go" packages = ["compute/metadata"] - pruneopts = "NUT" revision = "050b16d2314d5fc3d4c9a51e4cd5c7468e77f162" version = "v0.17.0" [[projects]] - digest = "1:5266e4aea300dc93075980b9e852f9c20a059da4988dcda3e36989c27b0cc475" name = "github.com/Azure/go-autorest" packages = [ "autorest", "autorest/adal", "autorest/azure", - "autorest/date", + "autorest/date" ] - pruneopts = "NUT" revision = "1ff28809256a84bb6966640ff3d0371af82ccba4" [[projects]] - digest = "1:a2c1d0e43bd3baaa071d1b9ed72c27d78169b2b269f71c105ac4ba34b1be4a39" name = "github.com/davecgh/go-spew" packages = ["spew"] - pruneopts = "NUT" revision = "346938d642f2ec3594ed81d874461961cd0faa76" version = "v1.1.0" [[projects]] - digest = "1:7a6852b35eb5bbc184561443762d225116ae630c26a7c4d90546619f1e7d2ad2" name = "github.com/dgrijalva/jwt-go" packages = ["."] - pruneopts = "NUT" revision = "06ea1031745cb8b3dab3f6a236daf2b0aa468b7e" version = "v3.2.0" [[projects]] - digest = "1:1b91ae0dc69a41d4c2ed23ea5cffb721ea63f5037ca4b81e6d6771fbb8f45129" name = "github.com/fsnotify/fsnotify" packages = ["."] - pruneopts = "NUT" revision = "c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9" version = "v1.4.7" [[projects]] - digest = "1:abfe129dc92b16fbf0cc9d6336096a2823151756f62072a700eb10754141b38e" name = "github.com/ghodss/yaml" packages = ["."] - pruneopts = "NUT" revision = "73d445a93680fa1a78ae23a5839bad48f32ba1ee" [[projects]] branch = "v2" - digest = "1:13e704c08924325be00f96e47e7efe0bfddf0913cdfc237423c83f9b183ff590" name = "github.com/go-yaml/yaml" packages = ["."] - pruneopts = "NUT" revision = "d670f9405373e636a5a2765eea47fac0c9bc91a4" [[projects]] - digest = "1:26a5b0d17fc9534a39ab910cbe61ffa5059a9e608e1a0e3c2663d526b05f1081" name = "github.com/gogo/protobuf" packages = [ "proto", - "sortkeys", + "sortkeys" ] - pruneopts = "NUT" revision = "c0656edd0d9eab7c66d1eb0c568f9039345796f7" [[projects]] - digest = "1:78b8040ece2ff622580def2708b9eb0b2857711b6744c475439bf337e9c677ea" name = "github.com/golang/glog" packages = ["."] - pruneopts = "NUT" revision = "44145f04b68cf362d9c4df2182967c2275eaefed" [[projects]] - digest = "1:7672c206322f45b33fac1ae2cb899263533ce0adcc6481d207725560208ec84e" name = "github.com/golang/groupcache" packages = ["lru"] - pruneopts = "NUT" revision = "02826c3e79038b59d737d3b1c0a1d937f71a4433" [[projects]] - digest = "1:62c39e48b3af4ccc5f20819b3fc4b7aee88cf4b7e296c4be0168113e755adfaa" name = "github.com/golang/protobuf" packages = [ "proto", "ptypes", "ptypes/any", "ptypes/duration", - "ptypes/timestamp", + "ptypes/timestamp" ] - pruneopts = "NUT" revision = "1643683e1b54a9e88ad26d98f81400c8c9d9f4f9" [[projects]] branch = "master" - digest = "1:245bd4eb633039cd66106a5d340ae826d87f4e36a8602fcc940e14176fd26ea7" name = "github.com/google/btree" packages = ["."] - pruneopts = "NUT" revision = "e89373fe6b4a7413d7acd6da1725b83ef713e6e4" [[projects]] - digest = "1:21c8b3a5b2d66f5ba6731f12133ccbf970947a6f4e78f0d46b64c49f8a4034c1" name = "github.com/google/go-cmp" packages = [ "cmp", "cmp/internal/diff", "cmp/internal/function", - "cmp/internal/value", + "cmp/internal/value" ] - pruneopts = "NUT" revision = "3af367b6b30c263d47e8895973edcca9a49cf029" version = "v0.2.0" [[projects]] - digest = "1:f9425215dccf1c63f659ec781ca46bc81804341821d0cd8d2459c5b58f8bd067" name = "github.com/google/gofuzz" packages = ["."] - pruneopts = "NUT" revision = "44d81051d367757e1c7c6a5a86423ece9afcf63c" [[projects]] - digest = "1:fc56ff1b4b04575628f199eb0bc60fa6ed8ff63196e290151a5031c6af5eaef4" name = "github.com/googleapis/gnostic" packages = [ "OpenAPIv2", "compiler", - "extensions", + "extensions" ] - pruneopts = "NUT" revision = "0c5108395e2debce0d731cf0287ddf7242066aba" [[projects]] branch = "master" - digest = "1:4dc485b85c4dd43ebc0258760edab229c6cce4d0ac0ca262bd93cf8456b24f26" name = "github.com/gophercloud/gophercloud" packages = [ ".", @@ -147,143 +116,109 @@ "openstack/identity/v2/tokens", "openstack/identity/v3/tokens", "openstack/utils", - "pagination", + "pagination" ] - pruneopts = "NUT" revision = "19d3956666f33e02b023e9a2299a7d428cd9768a" [[projects]] branch = "master" - digest = "1:a1db0214936912602a7a8cedc09a2e3211f5c097dc89189fb4b3bc86346c9e89" name = "github.com/gregjones/httpcache" packages = [ ".", - "diskcache", + "diskcache" ] - pruneopts = "NUT" revision = "9cad4c3443a7200dd6400aef47183728de563a38" [[projects]] - digest = "1:475b179287e8afdcd352014b2c2500e67decdf63e66125e2129286873453e1cd" name = "github.com/hashicorp/golang-lru" packages = [ ".", - "simplelru", + "simplelru" ] - pruneopts = "NUT" revision = "a0d98a5f288019575c6d1f4bb1573fef2d1fcdc4" [[projects]] - digest = "1:8f5fa95e43ab4a43056b7b65ec1614b4440f33bbfef2fa0a4d4707aedcb1a023" name = "github.com/imdario/mergo" packages = ["."] - pruneopts = "NUT" revision = "6633656539c1639d9d78127b7d47c622b5d7b6dc" [[projects]] branch = "master" - digest = "1:0dccfafe61a6185593a61043d268cb62a847a8a144eb7a1476cc4b519e976bb2" name = "github.com/josephburnett/k8sflag" packages = ["pkg/k8sflag"] - pruneopts = "NUT" revision = "eaf31dc5c82d361eba9d4a94739d6d67ddbb59c9" [[projects]] - digest = "1:0243cffa4a3410f161ee613dfdd903a636d07e838a42d341da95d81f42cd1d41" name = "github.com/json-iterator/go" packages = ["."] - pruneopts = "NUT" revision = "f2b4162afba35581b6d4a50d3b8f34e33c144682" [[projects]] branch = "master" - digest = "1:572bdae08e090e4b36d6f04ccb44576c80eeccf3964123446cc3e5079857f355" name = "github.com/knative/pkg" packages = ["signals"] - pruneopts = "NUT" revision = "f4a77d77082cf7efcc4cf8949f8d85e3967ebde1" [[projects]] branch = "master" - digest = "1:d6415e6b744ec877c21fe734067636b9ee149af77276b08a3d33dd8698abf947" name = "github.com/knative/test-infra" packages = ["."] - pruneopts = "T" revision = "4a4a682ee1fd31f33e450406393c3553b9ec5c2a" [[projects]] branch = "master" - digest = "1:0e9bfc47ab9941ecc3344e580baca5deb4091177e84dd9773b48b38ec26b93d5" name = "github.com/mattbaird/jsonpatch" packages = ["."] - pruneopts = "NUT" revision = "81af80346b1a01caae0cbc27fd3c1ba5b11e189f" [[projects]] - digest = "1:2f42fa12d6911c7b7659738758631bec870b7e9b4c6be5444f963cdcfccc191f" name = "github.com/modern-go/concurrent" packages = ["."] - pruneopts = "NUT" revision = "bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94" version = "1.0.3" [[projects]] - digest = "1:c6aca19413b13dc59c220ad7430329e2ec454cc310bc6d8de2c7e2b93c18a0f6" name = "github.com/modern-go/reflect2" packages = ["."] - pruneopts = "NUT" revision = "4b7aa43c6742a2c18fdef89dd197aaae7dac7ccd" version = "1.0.1" [[projects]] branch = "master" - digest = "1:3bf17a6e6eaa6ad24152148a631d18662f7212e21637c2699bff3369b7f00fa2" name = "github.com/petar/GoLLRB" packages = ["llrb"] - pruneopts = "NUT" revision = "53be0d36a84c2a886ca057d34b6aa4468df9ccb4" [[projects]] - digest = "1:6c6d91dc326ed6778783cff869c49fb2f61303cdd2ebbcf90abe53505793f3b6" name = "github.com/peterbourgon/diskv" packages = ["."] - pruneopts = "NUT" revision = "5f041e8faa004a95c88a202771f4cc3e991971e6" version = "v2.0.1" [[projects]] - digest = "1:d917313f309bda80d27274d53985bc65651f81a5b66b820749ac7f8ef061fd04" name = "github.com/sergi/go-diff" packages = ["diffmatchpatch"] - pruneopts = "NUT" revision = "1744e2970ca51c86172c8190fadad617561ed6e7" version = "v1.0.0" [[projects]] - digest = "1:15e5c398fbd9d2c439b635a08ac161b13d04f0c2aa587fe256b65dc0c3efe8b7" name = "github.com/spf13/pflag" packages = ["."] - pruneopts = "NUT" revision = "583c0c0531f06d5278b7d917446061adc344b5cd" [[projects]] - digest = "1:22f696cee54865fb8e9ff91df7b633f6b8f22037a8015253c6b6a71ca82219c7" name = "go.uber.org/atomic" packages = ["."] - pruneopts = "NUT" revision = "1ea20fb1cbb1cc08cbd0d913a96dead89aa18289" version = "v1.3.2" [[projects]] - digest = "1:58ca93bdf81bac106ded02226b5395a0595d5346cdc4caa8d9c1f3a5f8f9976e" name = "go.uber.org/multierr" packages = ["."] - pruneopts = "NUT" revision = "3c4937480c32f4c13a875a1829af76c98ca3d40a" version = "v1.1.0" [[projects]] - digest = "1:a607c955b5f17d6320c592a1d3a39f6a63e8ded44f7990dc5846d0714cb32758" name = "go.uber.org/zap" packages = [ ".", @@ -291,21 +226,17 @@ "internal/bufferpool", "internal/color", "internal/exit", - "zapcore", + "zapcore" ] - pruneopts = "NUT" revision = "eeedf312bc6c57391d84767a4cd413f02a917974" version = "v1.8.0" [[projects]] - digest = "1:624a05c7c6ed502bf77364cd3d54631383dafc169982fddd8ee77b53c3d9cccf" name = "golang.org/x/crypto" packages = ["ssh/terminal"] - pruneopts = "NUT" revision = "81e90905daefcd6fd217b62423c0908922eadb30" [[projects]] - digest = "1:02ccbca876321f757c25b1cc794cb1c71362aa86c74fa31cf21c4688b114c088" name = "golang.org/x/net" packages = [ "context", @@ -313,37 +244,31 @@ "http2", "http2/hpack", "idna", - "lex/httplex", + "lex/httplex" ] - pruneopts = "NUT" revision = "1c05540f6879653db88113bc4a2b70aec4bd491f" [[projects]] branch = "master" - digest = "1:ba88eef443e86a78978bc7c6cbf56c12925983ef35f8d65fc3867186a6fcbbf3" name = "golang.org/x/oauth2" packages = [ ".", "google", "internal", "jws", - "jwt", + "jwt" ] - pruneopts = "NUT" revision = "30785a2c434e431ef7c507b54617d6a951d5f2b4" [[projects]] - digest = "1:d80b37b725351dfdd74022614569420d65e377cf9bf1d58dbf91c3aacc1e27c6" name = "golang.org/x/sys" packages = [ "unix", - "windows", + "windows" ] - pruneopts = "NUT" revision = "95c6576299259db960f6c5b9b69ea52422860fce" [[projects]] - digest = "1:11e5ba605f499e37162cc8ca25fb16d6ff66fbfdbdc43c92d6f1351cde975413" name = "golang.org/x/text" packages = [ "internal/gen", @@ -354,32 +279,26 @@ "unicode/bidi", "unicode/cldr", "unicode/norm", - "unicode/rangetable", + "unicode/rangetable" ] - pruneopts = "NUT" revision = "b19bf474d317b857955b12035d2c5acb57ce8b01" [[projects]] branch = "master" - digest = "1:51a479a09b7ed06b7be5a854e27fcc328718ae0e5ad159f9ddeef12d0326c2e7" name = "golang.org/x/time" packages = ["rate"] - pruneopts = "NUT" revision = "26559e0f760e39c24d730d3224364aef164ee23f" [[projects]] branch = "master" - digest = "1:c765c0e7646900b1d5f1feecd2d255fcadd04ab9757ef792f5b5a4ffcb633407" name = "golang.org/x/tools" packages = [ "go/ast/astutil", - "imports", + "imports" ] - pruneopts = "NUT" revision = "66487607e2081c7c2af2281c62c14ee000d5024b" [[projects]] - digest = "1:91da4958962c8e23fbad8789970931a6bcc749bfbe242d3594dfea7b628ff275" name = "google.golang.org/appengine" packages = [ ".", @@ -391,30 +310,24 @@ "internal/modules", "internal/remote_api", "internal/urlfetch", - "urlfetch", + "urlfetch" ] - pruneopts = "NUT" revision = "150dc57a1b433e64154302bdc40b6bb8aefa313a" version = "v1.0.0" [[projects]] - digest = "1:ef72505cf098abdd34efeea032103377bec06abb61d8a06f002d5d296a4b1185" name = "gopkg.in/inf.v0" packages = ["."] - pruneopts = "NUT" revision = "3887ee99ecf07df5b447e9b00d9c0b2adaa9f3e4" version = "v0.9.0" [[projects]] - digest = "1:7c95b35057a0ff2e19f707173cc1a947fa43a6eb5c4d300d196ece0334046082" name = "gopkg.in/yaml.v2" packages = ["."] - pruneopts = "NUT" revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183" version = "v2.2.1" [[projects]] - digest = "1:901adc2b5cec68bcc4568ebfb909520940739c0670089ff3f6a298dcd757276d" name = "k8s.io/api" packages = [ "admission/v1beta1", @@ -446,14 +359,12 @@ "settings/v1alpha1", "storage/v1", "storage/v1alpha1", - "storage/v1beta1", + "storage/v1beta1" ] - pruneopts = "NUT" revision = "072894a440bdee3a891dea811fe42902311cd2a3" version = "kubernetes-1.11.0" [[projects]] - digest = "1:cdd93d1f3d8cde772f1e0ec7e729be1b18b27cdc8ca7fa0315dd03a127fc5090" name = "k8s.io/apimachinery" packages = [ "pkg/api/errors", @@ -497,14 +408,12 @@ "pkg/version", "pkg/watch", "third_party/forked/golang/json", - "third_party/forked/golang/reflect", + "third_party/forked/golang/reflect" ] - pruneopts = "NUT" revision = "103fd098999dc9c0c88536f5c9ad2e5da39373ae" version = "kubernetes-1.11.0" [[projects]] - digest = "1:49371ac02787d0b72658bc918cd67b5b650448a6991fde08736068d0aee69929" name = "k8s.io/client-go" packages = [ "discovery", @@ -669,14 +578,12 @@ "util/integer", "util/jsonpath", "util/retry", - "util/workqueue", + "util/workqueue" ] - pruneopts = "NUT" revision = "7d04d0e2a0a1a4d4a1cd6baa432a2301492e4e65" version = "kubernetes-1.11.0" [[projects]] - digest = "1:8ef6969f2d9c279c0446c53479b7d4237944b0d2536e1d2be5405d08413fba66" name = "k8s.io/code-generator" packages = [ "cmd/client-gen", @@ -697,15 +604,13 @@ "cmd/lister-gen", "cmd/lister-gen/args", "cmd/lister-gen/generators", - "pkg/util", + "pkg/util" ] - pruneopts = "T" revision = "6702109cc68eb6fe6350b83e14407c8d7309fd1a" version = "kubernetes-1.11.0" [[projects]] branch = "master" - digest = "1:cc02b96a3307a2b9534890fb6bc1c0427319aa8f9ffd6797ba97587fc8874f80" name = "k8s.io/gengo" packages = [ "args", @@ -715,67 +620,18 @@ "generator", "namer", "parser", - "types", + "types" ] - pruneopts = "NUT" revision = "8394c995ab8fbe52216f38d0e1a37de36d820528" [[projects]] - digest = "1:7d46c560bdf2e3d01268acf4f376480124d40718bebd4e7ed8f1eedc372480cf" name = "k8s.io/kube-openapi" packages = ["pkg/util/proto"] - pruneopts = "NUT" revision = "39a7bf85c140f972372c2a0d1ee40adbf0c8bfe1" [solve-meta] analyzer-name = "dep" analyzer-version = 1 - input-imports = [ - "github.com/go-yaml/yaml", - "github.com/google/go-cmp/cmp", - "github.com/josephburnett/k8sflag/pkg/k8sflag", - "github.com/knative/pkg/signals", - "github.com/mattbaird/jsonpatch", - "github.com/sergi/go-diff/diffmatchpatch", - "go.uber.org/zap", - "go.uber.org/zap/zapcore", - "k8s.io/api/admission/v1beta1", - "k8s.io/api/admissionregistration/v1beta1", - "k8s.io/api/core/v1", - "k8s.io/api/extensions/v1beta1", - "k8s.io/apimachinery/pkg/api/errors", - "k8s.io/apimachinery/pkg/apis/meta/v1", - "k8s.io/apimachinery/pkg/fields", - "k8s.io/apimachinery/pkg/labels", - "k8s.io/apimachinery/pkg/runtime", - "k8s.io/apimachinery/pkg/runtime/schema", - "k8s.io/apimachinery/pkg/runtime/serializer", - "k8s.io/apimachinery/pkg/types", - "k8s.io/apimachinery/pkg/util/runtime", - "k8s.io/apimachinery/pkg/util/sets/types", - "k8s.io/apimachinery/pkg/util/wait", - "k8s.io/apimachinery/pkg/watch", - "k8s.io/client-go/discovery", - "k8s.io/client-go/discovery/fake", - "k8s.io/client-go/informers", - "k8s.io/client-go/kubernetes", - "k8s.io/client-go/kubernetes/fake", - "k8s.io/client-go/kubernetes/scheme", - "k8s.io/client-go/kubernetes/typed/admissionregistration/v1beta1", - "k8s.io/client-go/kubernetes/typed/core/v1", - "k8s.io/client-go/plugin/pkg/client/auth", - "k8s.io/client-go/rest", - "k8s.io/client-go/testing", - "k8s.io/client-go/tools/cache", - "k8s.io/client-go/tools/clientcmd", - "k8s.io/client-go/tools/record", - "k8s.io/client-go/util/flowcontrol", - "k8s.io/client-go/util/workqueue", - "k8s.io/code-generator/cmd/client-gen", - "k8s.io/code-generator/cmd/deepcopy-gen", - "k8s.io/code-generator/cmd/defaulter-gen", - "k8s.io/code-generator/cmd/informer-gen", - "k8s.io/code-generator/cmd/lister-gen", - ] + inputs-digest = "908cce7bf838c1d6d50b0ac1b34633d951103be803a9f264a236f9b161635d92" solver-name = "gps-cdcl" solver-version = 1 diff --git a/pkg/apis/build/v1alpha1/build_types.go b/pkg/apis/build/v1alpha1/build_types.go index 03dd1109..cc595e07 100644 --- a/pkg/apis/build/v1alpha1/build_types.go +++ b/pkg/apis/build/v1alpha1/build_types.go @@ -189,7 +189,9 @@ type BuildStatus struct { // Google provides additional information if the builder is Google. Google *GoogleSpec `json:"google,omitempty"` - // StartTime is the time the build started. + // Creation is the time the build is created. + CreationTime metav1.Time `json:"creationTime,omitEmpty"` + // StartTime is the time the build is actually started. StartTime metav1.Time `json:"startTime,omitEmpty"` // CompletionTime is the time the build completed. CompletionTime metav1.Time `json:"completionTime,omitEmpty"` @@ -198,7 +200,7 @@ type BuildStatus struct { StepStates []corev1.ContainerState `json:"stepStates,omitEmpty"` // Conditions describes the set of conditions of this build. Conditions []BuildCondition `json:"conditions,omitempty"` - + // StepsCompleted lists the name of build steps completed. StepsCompleted []string `json:"stepsCompleted"` } diff --git a/pkg/apis/build/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/build/v1alpha1/zz_generated.deepcopy.go index 1982ff6f..af4d93f8 100644 --- a/pkg/apis/build/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/build/v1alpha1/zz_generated.deepcopy.go @@ -194,6 +194,7 @@ func (in *BuildStatus) DeepCopyInto(out *BuildStatus) { **out = **in } } + in.CreationTime.DeepCopyInto(&out.CreationTime) in.StartTime.DeepCopyInto(&out.StartTime) in.CompletionTime.DeepCopyInto(&out.CompletionTime) if in.StepStates != nil { diff --git a/pkg/builder/cluster/builder.go b/pkg/builder/cluster/builder.go index f4ee6cd4..32c9ea5d 100644 --- a/pkg/builder/cluster/builder.go +++ b/pkg/builder/cluster/builder.go @@ -21,8 +21,10 @@ import ( "fmt" "sync" + "github.com/knative/build/pkg/builder/cluster/convert" "go.uber.org/zap" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" kubeinformers "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes" @@ -30,7 +32,6 @@ import ( v1alpha1 "github.com/knative/build/pkg/apis/build/v1alpha1" buildercommon "github.com/knative/build/pkg/builder" - "github.com/knative/build/pkg/builder/cluster/convert" ) type operation struct { @@ -52,7 +53,8 @@ func (op *operation) Checkpoint(status *v1alpha1.BuildStatus) error { } status.Cluster.Namespace = op.namespace status.Cluster.PodName = op.Name() - status.StartTime = op.startTime + status.CreationTime = op.startTime + status.StartTime = op.builder.podCreationTime status.StepStates = nil status.StepsCompleted = nil for _, s := range op.statuses { @@ -70,7 +72,17 @@ func (op *operation) Checkpoint(status *v1alpha1.BuildStatus) error { } func (op *operation) Terminate() error { - return op.builder.kubeclient.CoreV1().Pods(op.namespace).Delete(op.name, &metav1.DeleteOptions{}) + if err := op.builder.kubeclient.CoreV1().Pods(op.namespace).Delete(op.name, &metav1.DeleteOptions{}); err != nil && !errors.IsNotFound(err) { + return err + } + return nil +} + +func getStartTime(m *metav1.Time) metav1.Time { + if m == nil { + return metav1.Time{} + } + return *m } func (op *operation) Wait() (*v1alpha1.BuildStatus, error) { @@ -101,7 +113,8 @@ func (op *operation) Wait() (*v1alpha1.BuildStatus, error) { Namespace: op.namespace, PodName: op.Name(), }, - StartTime: op.startTime, + CreationTime: op.startTime, + StartTime: op.builder.podCreationTime, CompletionTime: metav1.Now(), StepStates: states, StepsCompleted: stepsCompleted, @@ -177,8 +190,9 @@ type builder struct { // send a completion notification when we see that Pod complete. // On success, an empty string is sent. // On failure, the Message of the failure PodCondition is sent. - callbacks map[string]chan *corev1.Pod - logger *zap.SugaredLogger + callbacks map[string]chan *corev1.Pod + logger *zap.SugaredLogger + podCreationTime metav1.Time } func (b *builder) Builder() v1alpha1.BuildProvider { @@ -212,12 +226,12 @@ func (b *builder) OperationFromStatus(status *v1alpha1.BuildStatus) (buildercomm for _, state := range status.StepStates { statuses = append(statuses, corev1.ContainerStatus{State: state}) } - + b.podCreationTime = status.CreationTime return &operation{ builder: b, namespace: status.Cluster.Namespace, name: status.Cluster.PodName, - startTime: status.StartTime, + startTime: status.CreationTime, statuses: statuses, }, nil } @@ -253,6 +267,7 @@ func (b *builder) addPodEvent(obj interface{}) { b.mux.Lock() defer b.mux.Unlock() key := getKey(pod.Namespace, pod.Name) + b.podCreationTime = getStartTime(pod.Status.StartTime) if ch, ok := b.callbacks[key]; ok { // Send the person listening the message. diff --git a/pkg/builder/cluster/builder_test.go b/pkg/builder/cluster/builder_test.go index 16743c7f..cd48e0c0 100644 --- a/pkg/builder/cluster/builder_test.go +++ b/pkg/builder/cluster/builder_test.go @@ -67,12 +67,15 @@ func TestBasicFlow(t *testing.T) { if buildercommon.IsDone(&bs) { t.Errorf("IsDone(%v); wanted not done, got done.", bs) } - if bs.StartTime.IsZero() { - t.Errorf("bs.StartTime; want non-zero, got %v", bs.StartTime) + if bs.CreationTime.IsZero() { + t.Errorf("bs.CreationTime; want zero, got %v", bs.CreationTime) } if !bs.CompletionTime.IsZero() { t.Errorf("bs.CompletionTime; want zero, got %v", bs.CompletionTime) } + if !bs.StartTime.IsZero() { + t.Errorf("bs.StartTime; want non-zero, got %v", bs.StartTime) + } op, err = builder.OperationFromStatus(&bs) if err != nil { t.Fatalf("Unexpected error executing OperationFromStatus: %v", err) @@ -101,11 +104,14 @@ func TestBasicFlow(t *testing.T) { if msg, failed := buildercommon.ErrorMessage(status); failed { t.Errorf("ErrorMessage(%v); wanted not failed, got %q", status, msg) } + if status.CompletionTime.IsZero() { + t.Errorf("status.CompletionTime; want non-zero, got %v", status.CompletionTime) + } if status.StartTime.IsZero() { t.Errorf("status.StartTime; want non-zero, got %v", status.StartTime) } - if status.CompletionTime.IsZero() { - t.Errorf("status.CompletionTime; want non-zero, got %v", status.CompletionTime) + if status.CreationTime.IsZero() { + t.Errorf("status.CreationTime; want non-zero, got %v", status.CreationTime) } }() // Wait until the test thread is ready for us to update things. @@ -117,6 +123,8 @@ func TestBasicFlow(t *testing.T) { if err != nil { t.Fatalf("Unexpected error fetching Pod: %v", err) } + pod.Status.StartTime = &metav1.Time{Time: time.Now()} + // Now modify it to look done. pod.Status.Phase = corev1.PodSucceeded pod, err = podsclient.Update(pod) @@ -162,12 +170,15 @@ func TestNonFinalUpdateFlow(t *testing.T) { if buildercommon.IsDone(&bs) { t.Errorf("IsDone(%v); wanted not done, got done.", bs) } - if bs.StartTime.IsZero() { - t.Errorf("bs.StartTime; want non-zero, got %v", bs.StartTime) + if bs.CreationTime.IsZero() { + t.Errorf("bs.CreationTime; want zero, got %v", bs.CreationTime) } if !bs.CompletionTime.IsZero() { t.Errorf("bs.CompletionTime; want zero, got %v", bs.CompletionTime) } + if !bs.StartTime.IsZero() { + t.Errorf("bs.StartTime; want non-zero, got %v", bs.StartTime) + } op, err = builder.OperationFromStatus(&bs) if err != nil { t.Fatalf("Unexpected error executing OperationFromStatus: %v", err) @@ -185,8 +196,8 @@ func TestNonFinalUpdateFlow(t *testing.T) { if err != nil { t.Fatalf("Unexpected error waiting for builder.Operation: %v", err) } - if status.StartTime.IsZero() { - t.Errorf("status.StartTime; want non-zero, got %v", status.StartTime) + if status.CreationTime.IsZero() { + t.Errorf("status.CreationTime; want non-zero, got %v", status.CreationTime) } if status.CompletionTime.IsZero() { t.Errorf("status.CompletionTime; want non-zero, got %v", status.CompletionTime) @@ -203,6 +214,8 @@ func TestNonFinalUpdateFlow(t *testing.T) { } // Make a non-terminal modification pod.Status.Phase = corev1.PodRunning + pod.Status.StartTime = &metav1.Time{Time: time.Now()} + pod, err = podsclient.Update(pod) if err != nil { t.Fatalf("Unexpected error updating Pod: %v", err) @@ -254,12 +267,15 @@ func TestFailureFlow(t *testing.T) { if buildercommon.IsDone(&bs) { t.Errorf("IsDone(%v); wanted not done, got done.", bs) } - if bs.StartTime.IsZero() { - t.Errorf("bs.StartTime; want non-zero, got %v", bs.StartTime) + if bs.CreationTime.IsZero() { + t.Errorf("bs.CreationTime; want zero, got %v", bs.CreationTime) } if !bs.CompletionTime.IsZero() { t.Errorf("bs.CompletionTime; want zero, got %v", bs.CompletionTime) } + if !bs.StartTime.IsZero() { + t.Errorf("bs.StartTime; want non-zero, got %v", bs.StartTime) + } op, err = builder.OperationFromStatus(&bs) if err != nil { t.Fatalf("Unexpected error executing OperationFromStatus: %v", err) @@ -288,12 +304,15 @@ func TestFailureFlow(t *testing.T) { if msg, failed := buildercommon.ErrorMessage(status); !failed || msg != expectedErrorMessage { t.Errorf("ErrorMessage(%v); wanted %q, got %q", status, expectedErrorMessage, msg) } - if status.StartTime.IsZero() { - t.Errorf("status.StartTime; want non-zero, got %v", status.StartTime) + if status.CreationTime.IsZero() { + t.Errorf("status.CreationTime; want non-zero, got %v", status.CreationTime) } if status.CompletionTime.IsZero() { t.Errorf("status.CompletionTime; want non-zero, got %v", status.CompletionTime) } + if status.StartTime.IsZero() { + t.Errorf("status.StartTime; want non-zero, got %v", status.StartTime) + } if len(status.StepStates) != 1 { t.Errorf("StepStates contained %d states, want 1: %+v", len(status.StepStates), status.StepStates) } else if status.StepStates[0].Terminated.Reason != expectedErrorReason { @@ -319,6 +338,7 @@ func TestFailureFlow(t *testing.T) { }, }, }} + pod.Status.StartTime = &metav1.Time{Time: time.Now()} pod, err = podsclient.Update(pod) if err != nil { t.Fatalf("Unexpected error updating Pod: %v", err) @@ -352,12 +372,15 @@ func TestPodPendingFlow(t *testing.T) { if buildercommon.IsDone(&bs) { t.Errorf("IsDone(%v); wanted not done, got done.", bs) } - if bs.StartTime.IsZero() { - t.Errorf("bs.StartTime; want non-zero, got %v", bs.StartTime) + if bs.CreationTime.IsZero() { + t.Errorf("bs.CreationTime; want zero, got %v", bs.CreationTime) } if !bs.CompletionTime.IsZero() { t.Errorf("bs.CompletionTime; want zero, got %v", bs.CompletionTime) } + if !bs.StartTime.IsZero() { + t.Errorf("bs.StartTime; want non-zero, got %v", bs.StartTime) + } op, err = builder.OperationFromStatus(&bs) if err != nil { t.Fatalf("Unexpected error executing OperationFromStatus: %v", err) @@ -386,6 +409,9 @@ func TestPodPendingFlow(t *testing.T) { if msg := statusMessage(status); msg != expectedPendingMsg { t.Errorf("ErrorMessage(%v); wanted %q, got %q", status, expectedPendingMsg, msg) } + if status.CreationTime.IsZero() { + t.Errorf("status.CreationTime; want non-zero, got %v", status.CreationTime) + } if status.StartTime.IsZero() { t.Errorf("status.StartTime; want non-zero, got %v", status.StartTime) } @@ -418,6 +444,7 @@ func TestPodPendingFlow(t *testing.T) { }, }, }} + pod.Status.StartTime = &metav1.Time{Time: time.Now()} pod, err = podsclient.Update(pod) if err != nil { t.Fatalf("Unexpected error updating Pod: %v", err) @@ -459,7 +486,10 @@ func TestStepFailureFlow(t *testing.T) { if buildercommon.IsDone(&bs) { t.Errorf("IsDone(%v); wanted not done, got done.", bs) } - if bs.StartTime.IsZero() { + if bs.CreationTime.IsZero() { + t.Errorf("bs.CreationTime; want zero, got %v", bs.CreationTime) + } + if !bs.StartTime.IsZero() { t.Errorf("bs.StartTime; want non-zero, got %v", bs.StartTime) } if !bs.CompletionTime.IsZero() { @@ -495,6 +525,9 @@ func TestStepFailureFlow(t *testing.T) { !strings.Contains(msg, `"step-name"`) || !strings.Contains(msg, "128") { t.Errorf("ErrorMessage(%v); got %q, want %q", status, msg, expectedErrorMessage) } + if status.CreationTime.IsZero() { + t.Errorf("status.CreationTime; got %v, want non-zero", status.CreationTime) + } if status.StartTime.IsZero() { t.Errorf("status.StartTime; got %v, want non-zero", status.StartTime) } @@ -523,6 +556,7 @@ func TestStepFailureFlow(t *testing.T) { ImageID: "docker-pullable://ubuntu@sha256:deadbeef", }} pod.Status.Message = "don't expect this!" + pod.Status.StartTime = &metav1.Time{Time: time.Now()} pod, err = podsclient.Update(pod) if err != nil { diff --git a/pkg/builder/interface.go b/pkg/builder/interface.go index 4b8086ee..6a6fb671 100644 --- a/pkg/builder/interface.go +++ b/pkg/builder/interface.go @@ -92,8 +92,7 @@ func IsTimeout(status *v1alpha1.BuildStatus, buildTimeout string) bool { return false } } - - return time.Since(status.StartTime.Time).Seconds() > timeout.Seconds() + return time.Since(status.CreationTime.Time).Seconds() > timeout.Seconds() } // ErrorMessage returns the error message from the status. diff --git a/pkg/builder/nop/builder.go b/pkg/builder/nop/builder.go index 9cfd30c5..45e4f264 100644 --- a/pkg/builder/nop/builder.go +++ b/pkg/builder/nop/builder.go @@ -47,6 +47,7 @@ func (nb *operation) Checkpoint(status *v1alpha1.BuildStatus) error { status.Google = &v1alpha1.GoogleSpec{} } status.Google.Operation = nb.Name() + status.CreationTime = startTime status.StartTime = startTime status.SetCondition(&v1alpha1.BuildCondition{ Type: v1alpha1.BuildSucceeded, @@ -67,6 +68,7 @@ func (nb *operation) Wait() (*v1alpha1.BuildStatus, error) { Google: &v1alpha1.GoogleSpec{ Operation: nb.Name(), }, + CreationTime: startTime, StartTime: startTime, CompletionTime: completionTime, } diff --git a/pkg/builder/nop/builder_test.go b/pkg/builder/nop/builder_test.go index 9f028261..8dc02555 100644 --- a/pkg/builder/nop/builder_test.go +++ b/pkg/builder/nop/builder_test.go @@ -45,6 +45,9 @@ func TestBasicFlow(t *testing.T) { if err != nil { t.Fatalf("Unexpected error executing OperationFromStatus: %v", err) } + if bs.CreationTime.IsZero() { + t.Errorf("bs.CreationTime; want non-zero, got %v", bs.CreationTime) + } if bs.StartTime.IsZero() { t.Errorf("bs.StartTime; want non-zero, got %v", bs.StartTime) } @@ -67,6 +70,9 @@ func TestBasicFlow(t *testing.T) { if msg, failed := buildercommon.ErrorMessage(status); failed { t.Errorf("ErrorMessage(%v); wanted not failed, got %q", status, msg) } + if status.CreationTime.IsZero() { + t.Errorf("status.CreationTime; want non-zero, got %v", status.CreationTime) + } if status.StartTime.IsZero() { t.Errorf("status.StartTime; want non-zero, got %v", status.StartTime) } diff --git a/pkg/controller/build/controller_test.go b/pkg/controller/build/controller_test.go index fdc502dd..f7d76035 100644 --- a/pkg/controller/build/controller_test.go +++ b/pkg/controller/build/controller_test.go @@ -145,7 +145,7 @@ func TestBasicFlows(t *testing.T) { t.Errorf("error fetching build: %v", err) } // Update status to current time - first.Status.StartTime = metav1.Now() + first.Status.CreationTime = metav1.Now() if builder.IsDone(&first.Status) { t.Errorf("First IsDone(%d); wanted not done, got done.", idx) @@ -232,12 +232,11 @@ func TestTimeoutFlows(t *testing.T) { bldr := &nop.Builder{} build := newBuild("test") - addBuffer, err := time.ParseDuration("10m") + buffer, err := time.ParseDuration("10m") if err != nil { t.Errorf("Error parsing duration") } - build.Status.StartTime.Time = metav1.Now().Time.Add(-addBuffer) build.Spec.Timeout = "1s" f := &fixture{ @@ -268,10 +267,9 @@ func TestTimeoutFlows(t *testing.T) { if err != nil { t.Errorf("error fetching build: %v", err) } - // Update status to current time - // first.Status.StartTime = metav1.Now() - first.Status.StartTime.Time = metav1.Now().Time.Add(-addBuffer) - first.Spec.Timeout = "1s" + + // Update status to past time by substracting buffer time + first.Status.CreationTime.Time = metav1.Now().Time.Add(-buffer) if builder.IsDone(&first.Status) { t.Error("First IsDone; wanted not done, got done.") diff --git a/test/bad-nodeselector/build-with-bad-selector.yaml b/test/bad-nodeselector/build-with-bad-selector.yaml new file mode 100644 index 00000000..51f9aafc --- /dev/null +++ b/test/bad-nodeselector/build-with-bad-selector.yaml @@ -0,0 +1,15 @@ +apiVersion: build.knative.dev/v1alpha1 +kind: Build +metadata: + name: test-build-with-badselector + labels: + expect: failed +spec: + timeout: 2m + steps: + - name: step1 + image: ubuntu + command: ["/bin/bash"] + args: ["-c", "sleep 15"] + nodeSelector: + disk: "fake-ssd" \ No newline at end of file diff --git a/test/columns.txt b/test/columns.txt index 571be051..30ee9f69 100644 --- a/test/columns.txt +++ b/test/columns.txt @@ -1,2 +1,2 @@ -NAME BUILDER TYPE STATUS START END -.metadata.name .status.builder .status.conditions[*].state .status.conditions[*].status .status.startTime .status.completionTime +NAME TYPE STATUS CREATED START END +.metadata.name .status.conditions[*].state .status.conditions[*].status .status.creationTime .status.startTime .status.completionTime