cmd-reporter runs a command and puts the results of the command into a ConfigMap defined by its `--config-map-name` commandline flag. cmd-reporter is intended to be run as a Kubernetes job where an operator needs to run a single command and get return information back from the command which is more than just success/failure. The ConfigMap returned includes `stdout`, `stderr`, and `retcode` data from the command. The ConfigMap may be preexisting, in which case cmd-reporter will overwrite the return information in the ConfigMap. cmd-reporter labels the ConfigMap with `app=cmd-reporter`, and if the ConfigMap already has an app label which is different, cmd-reporter fails without modifying the ConfigMap so as not to overwrite another application's data in the event of a ConfigMap name+namespace collision. Signed-off-by: Blaine Gardner <blaine.gardner@suse.com>
57 lines
2.1 KiB
Go
57 lines
2.1 KiB
Go
/*
|
|
Copyright 2019 The Rook Authors. All rights reserved.
|
|
|
|
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 util
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/rook/rook/cmd/rook/rook"
|
|
"github.com/rook/rook/pkg/daemon/util"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// CopyBinsCmd defines a top-level utility command which copies rook and tini binaries from the Rook
|
|
// container image to a directory.
|
|
var CopyBinsCmd = &cobra.Command{
|
|
Use: "copy-binaries",
|
|
Short: "Copy 'rook' and 'tini' binaries from a container to a given directory.",
|
|
Long: `Copy 'rook' and 'tini' binaries from a container to a given directory.
|
|
As an example, 'cmd-reporter run' may often need to be run from a container
|
|
other than the container containing the 'rook' binary. Use this command to copy
|
|
the 'rook' and required 'tini' binaries from the container containing the 'rook'
|
|
binary to a Kubernetes EmptyDir volume mounted at the given directory in a pod's
|
|
init container. From the pod's main container, mount the volume which now
|
|
contains the 'rook' and 'tini' binaries, and call 'rook cmd-reporter run' from
|
|
'tini' in order to run the desired command from a non-Rook container.`,
|
|
Args: cobra.NoArgs,
|
|
RunE: runCopyBins,
|
|
}
|
|
|
|
func init() {
|
|
// copy-binaries
|
|
CopyBinsCmd.Flags().StringVar(©ToDir, "copy-to-dir", "",
|
|
"The directory into which 'tini' and 'rook' binaries will be copied.")
|
|
CopyBinsCmd.MarkFlagRequired("copy-to-dir")
|
|
}
|
|
|
|
func runCopyBins(cCmd *cobra.Command, cArgs []string) error {
|
|
if err := util.CopyBinaries(copyToDir); err != nil {
|
|
rook.TerminateFatal(fmt.Errorf("could not copy binaries to %s. %+v", copyToDir, err))
|
|
}
|
|
return nil
|
|
}
|