istio.io/istio@v0.0.0-20240520182934-d79c90f27776/operator/cmd/mesh/verify.go (about) 1 // Copyright Istio Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package mesh 16 17 import ( 18 "fmt" 19 20 "github.com/spf13/cobra" 21 22 "istio.io/istio/istioctl/pkg/cli" 23 "istio.io/istio/istioctl/pkg/clioptions" 24 "istio.io/istio/istioctl/pkg/util" 25 "istio.io/istio/istioctl/pkg/util/formatting" 26 "istio.io/istio/operator/pkg/util/clog" 27 "istio.io/istio/operator/pkg/verifier" 28 ) 29 30 // NewVerifyCommand creates a new command for verifying Istio Installation Status 31 func NewVerifyCommand(ctx cli.Context) *cobra.Command { 32 var ( 33 filenames = []string{} 34 opts clioptions.ControlPlaneOptions 35 manifestsPath string 36 ) 37 verifyInstallCmd := &cobra.Command{ 38 Use: "verify-install [-f <deployment or istio operator file>] [--revision <revision>]", 39 Short: "Verifies Istio Installation Status", 40 Long: ` 41 verify-install verifies Istio installation status against the installation file 42 you specified when you installed Istio. It loops through all the installation 43 resources defined in your installation file and reports whether all of them are 44 in ready status. It will report failure when any of them are not ready. 45 46 If you do not specify an installation it will check for an IstioOperator resource 47 and will verify if pods and services defined in it are present. 48 49 Note: For verifying whether your cluster is ready for Istio installation, see 50 istioctl experimental precheck. 51 `, 52 Example: ` # Verify that Istio is installed correctly via Istio Operator 53 istioctl verify-install 54 55 # Verify the deployment matches a custom Istio deployment configuration 56 istioctl verify-install -f $HOME/istio.yaml 57 58 # Verify the deployment matches the Istio Operator deployment definition 59 istioctl verify-install --revision <canary> 60 61 # Verify the installation of specific revision 62 istioctl verify-install -r 1-9-0`, 63 Args: func(cmd *cobra.Command, args []string) error { 64 if len(filenames) > 0 && opts.Revision != "" { 65 cmd.Println(cmd.UsageString()) 66 return fmt.Errorf("supply either a file or revision, but not both") 67 } 68 return nil 69 }, 70 RunE: func(c *cobra.Command, args []string) error { 71 client, err := ctx.CLIClient() 72 if err != nil { 73 return err 74 } 75 76 l := clog.NewConsoleLogger(c.OutOrStdout(), c.OutOrStderr(), installerScope) 77 client, kubeClient, err := KubernetesClients(client, l) 78 if err != nil { 79 return err 80 } 81 82 installationVerifier, err := verifier.NewStatusVerifier(client, kubeClient, 83 ctx.IstioNamespace(), manifestsPath, filenames, opts, verifier.WithLogger(l)) 84 if err != nil { 85 return err 86 } 87 if formatting.IstioctlColorDefault(c.OutOrStdout()) { 88 installationVerifier.Colorize() 89 } 90 return installationVerifier.Verify() 91 }, 92 } 93 94 flags := verifyInstallCmd.PersistentFlags() 95 flags.StringSliceVarP(&filenames, "filename", "f", filenames, "Istio YAML installation file.") 96 verifyInstallCmd.PersistentFlags().StringVarP(&manifestsPath, "manifests", "d", "", util.ManifestsFlagHelpStr) 97 opts.AttachControlPlaneFlags(verifyInstallCmd) 98 return verifyInstallCmd 99 }