-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added entrypoint log grabber to taskrun controller
What is the problem being solved? This PR addresses issue #143. This issue is that it when Build's complete, logs from the steps the Build ran are garbage collected by kubernetes and no longer available to the user. Why is this the best approach? 1) No special kubernetes configuration (eg. changing garbage collector values) What other approaches did you consider? 1) Changing kubernetes garbage collection for these containers so that they are not immediately deleted and log capture was possible What side effects will this approach have? 1) With this approach, users will have to specify the "Command" value for the containers they which to run as the Entrypoint is not retrievable. This means that containers/flows setup to use only the Entrypoint will no longer be supported. What future work remains to be done? 1) It is possible to have the PVCs changed to EmptyDir volumes once a log uploader is created. This will help with the issue that currently PVCs are being created and not cleaned up. Co-authored-by: Christie Wilson <christiewilson@google.com>
- Loading branch information
1 parent
1a65b67
commit 6f6b071
Showing
12 changed files
with
418 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
pkg/reconciler/v1alpha1/taskrun/resources/entrypoint.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
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 resources | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
const ( | ||
// MountName is the name of the pvc being mounted (which | ||
// will contain the entrypoint binary and eventually the logs) | ||
MountName = "tools" | ||
|
||
mountPoint = "/tools" | ||
entrypointBin = mountPoint + "/entrypoint" | ||
entrypointJSONConfigEnvVar = "ENTRYPOINT_OPTIONS" | ||
EntrypointImage = "gcr.io/k8s-prow/entrypoint@sha256:7c7cd8906ce4982ffee326218e9fc75da2d4896d53cabc9833b9cc8d2d6b2b8f" | ||
) | ||
|
||
var toolsMount = corev1.VolumeMount{ | ||
Name: MountName, | ||
MountPath: mountPoint, | ||
} | ||
|
||
// GetCopyStep will return a Build Step (Container) that will | ||
// copy the entrypoint binary from the entrypoint image into the | ||
// volume mounted at mountPoint, so that it can be mounted by | ||
// subsequent steps and used to capture logs. | ||
func GetCopyStep() corev1.Container { | ||
return corev1.Container{ | ||
Name: "place-tools", | ||
Image: EntrypointImage, | ||
Command: []string{"/bin/cp"}, | ||
Args: []string{"/entrypoint", entrypointBin}, | ||
VolumeMounts: []corev1.VolumeMount{toolsMount}, | ||
} | ||
} | ||
|
||
type entrypointArgs struct { | ||
Args []string `json:"args"` | ||
ProcessLog string `json:"process_log"` | ||
MarkerFile string `json:"marker_file"` | ||
} | ||
|
||
func getEnvVar(cmd, args []string) (string, error) { | ||
entrypointArgs := entrypointArgs{ | ||
Args: append(cmd, args...), | ||
ProcessLog: "/tools/process-log.txt", | ||
MarkerFile: "/tools/marker-file.txt", | ||
} | ||
j, err := json.Marshal(entrypointArgs) | ||
if err != nil { | ||
return "", fmt.Errorf("couldn't marshal arguments %q for entrypoint env var: %s", entrypointArgs, err) | ||
} | ||
return string(j), nil | ||
} | ||
|
||
// TODO: add more test cases after all, e.g. with existing env | ||
// var and volume mounts | ||
|
||
// AddEntrypoint will modify each of the steps/containers such that | ||
// the binary being run is no longer the one specified by the Command | ||
// and the Args, but is instead the entrypoint binary, which will | ||
// itself invoke the Command and Args, but also capture logs. | ||
// TODO: This will not work when a step uses an image that has its | ||
// own entrypoint, i.e. `Command` is a required field. In later iterations | ||
// we can update the controller to inspect the image's `Entrypoint` | ||
// and use that if required. | ||
func AddEntrypoint(steps []corev1.Container) error { | ||
for i := range steps { | ||
step := &steps[i] | ||
e, err := getEnvVar(step.Command, step.Args) | ||
if err != nil { | ||
return fmt.Errorf("couldn't get env var for entrypoint: %s", err) | ||
} | ||
step.Command = []string{entrypointBin} | ||
step.Args = []string{} | ||
|
||
step.Env = append(step.Env, corev1.EnvVar{ | ||
Name: entrypointJSONConfigEnvVar, | ||
Value: e, | ||
}) | ||
step.VolumeMounts = append(step.VolumeMounts, toolsMount) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.