mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-01-09 06:33:22 +00:00
* Convert ServerStatusRequest controller to controller-runtime Signed-off-by: Carlisia <carlisia@vmware.com> * Add select stm Signed-off-by: Carlisia <carlisia@vmware.com> * Fixed status patch bug Signed-off-by: Carlisia <carlisia@vmware.com> * Add mgr start Signed-off-by: Carlisia <carlisia@vmware.com> * Trying to sync Signed-off-by: Carlisia <carlisia@vmware.com> * Clean async now Signed-off-by: Carlisia <carlisia@vmware.com> * Clean up + move context out Signed-off-by: Carlisia <carlisia@vmware.com> * Bug: not closing the channel Signed-off-by: Carlisia <carlisia@vmware.com> * Clean up some tests Signed-off-by: Carlisia <carlisia@vmware.com> * Much better way to fetch an update using a backoff loop Signed-off-by: Carlisia <carlisia@vmware.com> * Even better way to retry: use apimachinery lib Signed-off-by: Carlisia <carlisia@vmware.com> * Refactor controller + add test Signed-off-by: Carlisia <carlisia@vmware.com> * partially fix unit tests Signed-off-by: Ashish Amarnath <ashisham@vmware.com> * Fix and add tests Signed-off-by: Carlisia <carlisia@vmware.com> * Add changelog Signed-off-by: Carlisia <carlisia@vmware.com> * Add ability to disable the controller + cleanups Signed-off-by: Carlisia <carlisia@vmware.com> * Fix bug w/ disabling controllers + fix test + clean up Signed-off-by: Carlisia <carlisia@vmware.com> * Move role.yaml to the correct folder Signed-off-by: Carlisia <carlisia@vmware.com> * Add sample serverstatusrequest.yaml Signed-off-by: Carlisia <carlisia@vmware.com> * Add requeue + better formatting Signed-off-by: Carlisia <carlisia@vmware.com> * Increase # of max concurrent reconciles Signed-off-by: Carlisia <carlisia@vmware.com> Co-authored-by: Ashish Amarnath <ashisham@vmware.com>
85 lines
2.4 KiB
Go
85 lines
2.4 KiB
Go
/*
|
|
Copyright 2017, 2019 the Velero contributors.
|
|
|
|
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 version
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/spf13/cobra"
|
|
kbclient "sigs.k8s.io/controller-runtime/pkg/client"
|
|
|
|
"github.com/vmware-tanzu/velero/pkg/buildinfo"
|
|
"github.com/vmware-tanzu/velero/pkg/client"
|
|
"github.com/vmware-tanzu/velero/pkg/cmd"
|
|
"github.com/vmware-tanzu/velero/pkg/cmd/cli/serverstatus"
|
|
)
|
|
|
|
func NewCommand(f client.Factory) *cobra.Command {
|
|
var clientOnly bool
|
|
timeout := 5 * time.Second
|
|
|
|
c := &cobra.Command{
|
|
Use: "version",
|
|
Short: "Print the velero version and associated image",
|
|
Run: func(c *cobra.Command, args []string) {
|
|
var kbClient kbclient.Client
|
|
if !clientOnly {
|
|
var err error
|
|
kbClient, err = f.KubebuilderClient()
|
|
cmd.CheckError(err)
|
|
}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
|
defer cancel()
|
|
|
|
serverStatusGetter := &serverstatus.DefaultServerStatusGetter{
|
|
Namespace: f.Namespace(),
|
|
Context: ctx,
|
|
}
|
|
printVersion(os.Stdout, clientOnly, kbClient, serverStatusGetter)
|
|
},
|
|
}
|
|
|
|
c.Flags().DurationVar(&timeout, "timeout", timeout, "maximum time to wait for server version to be reported. Default is 5 seconds.")
|
|
c.Flags().BoolVar(&clientOnly, "client-only", clientOnly, "only get velero client version, not server version")
|
|
|
|
return c
|
|
}
|
|
|
|
func printVersion(w io.Writer, clientOnly bool, kbClient kbclient.Client, serverStatusGetter serverstatus.ServerStatusGetter) {
|
|
fmt.Fprintln(w, "Client:")
|
|
fmt.Fprintf(w, "\tVersion: %s\n", buildinfo.Version)
|
|
fmt.Fprintf(w, "\tGit commit: %s\n", buildinfo.FormattedGitSHA())
|
|
|
|
if clientOnly {
|
|
return
|
|
}
|
|
|
|
serverStatus, err := serverStatusGetter.GetServerStatus(kbClient)
|
|
if err != nil {
|
|
fmt.Fprintf(w, "<error getting server version: %s>\n", err)
|
|
return
|
|
}
|
|
|
|
fmt.Fprintln(w, "Server:")
|
|
fmt.Fprintf(w, "\tVersion: %s\n", serverStatus.Status.ServerVersion)
|
|
}
|