pipeline/pkg/termination/termination.go
Dan Lorenc ea94852c3a Refactor Resource result output, and add support for Git resources.
This change builds upon #1406, and logs the exact Git commit used by a Git input
to the ResourceResults field.

Some other cleanups are included:
- Removing custom TerminationMessagePath from the Image resource. The default is fine.
- Test cleanup.
- A new helper to write termination messages from resource containers.

And finally, this adds a new environment variable to the git resource steps, indicating the
name of the resource instance they are running as. We should make this more generic and apply
it to all resource steps as part of the extensiblity refactor.
2019-10-17 09:09:20 -05:00

46 lines
1.3 KiB
Go

/*
Copyright 2019 The Tekton 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 termination
import (
"encoding/json"
"log"
"os"
v1alpha1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
"go.uber.org/zap"
)
func WriteMessage(logger *zap.SugaredLogger, path string, pro []v1alpha1.PipelineResourceResult) {
jsonOutput, err := json.Marshal(pro)
if err != nil {
logger.Fatalf("Error marshaling json: %s", err)
}
f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
log.Fatalf("Unexpected error converting output to json %v: %v", pro, err)
}
defer f.Close()
_, err = f.Write(jsonOutput)
if err != nil {
logger.Fatalf("Unexpected error converting output to json %v: %v", pro, err)
}
if err := f.Sync(); err != nil {
logger.Fatalf("Unexpected error converting output to json %v: %v", pro, err)
}
}