istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/ctrlz/options.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 ctrlz
    16  
    17  import (
    18  	"github.com/spf13/cobra"
    19  )
    20  
    21  // Options defines the set of options supported by Istio's ControlZ component introspection package.
    22  type Options struct {
    23  	// The IP port to use for ctrlz.
    24  	Port uint16
    25  
    26  	// The IP address to listen on for ctrlz.
    27  	Address string
    28  
    29  	// If true, pprof will be enabled
    30  	EnablePprof bool
    31  }
    32  
    33  // DefaultOptions returns a new set of options, initialized to the defaults
    34  func DefaultOptions() *Options {
    35  	return &Options{
    36  		Port:    9876,
    37  		Address: "localhost",
    38  	}
    39  }
    40  
    41  // AttachCobraFlags attaches a set of Cobra flags to the given Cobra command.
    42  //
    43  // Cobra is the command-line processor that Istio uses. This command attaches
    44  // the necessary set of flags to expose a CLI to let the user control all
    45  // introspection options.
    46  func (o *Options) AttachCobraFlags(cmd *cobra.Command) {
    47  	cmd.PersistentFlags().Uint16Var(&o.Port, "ctrlz_port", o.Port,
    48  		"The IP port to use for the ControlZ introspection facility")
    49  	cmd.PersistentFlags().StringVar(&o.Address, "ctrlz_address", o.Address,
    50  		"The IP Address to listen on for the ControlZ introspection facility. Use '*' to indicate all addresses.")
    51  }