Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var RootCmd = &cobra.Command{ Use: "operator", Short: "A brief description of your application", Long: `A longer description that spans multiple lines and likely contains examples and usage of using your application. For example: Cobra is a CLI library for Go that empowers applications. This application is a tool to generate the needed files to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { fmt.Println("my operator") config, err := clientcmd.BuildConfigFromFlags("", kubeconfig) if err != nil { panic(err.Error()) } clientset, err := kubernetes.NewForConfig(config) if err != nil { panic(err.Error()) } sharedInformerFactory := informers.NewSharedInformerFactoryWithOptions(clientset, time.Minute*1) controller := NewPodLoggingController(sharedInformerFactory) stop := make(chan struct{}) defer close(stop) err = controller.Run(stop) if err != nil { glog.Fatal(err) } select {} for { pods, err := clientset.CoreV1().Pods("").List(metav1.ListOptions{ ResourceVersion: "0", }) if err != nil { panic(err.Error()) } fmt.Printf("There are %d pods in the cluster\n", len(pods.Items)) namespace := "default" pod := "main001-000" _, err = clientset.CoreV1().Pods(namespace).Get(pod, metav1.GetOptions{}) if errors.IsNotFound(err) { fmt.Printf("Pod %s in namespace %s not found\n", pod, namespace) } else if statusError, isStatus := err.(*errors.StatusError); isStatus { fmt.Printf("Error getting pod %s in namespace %s: %v\n", pod, namespace, statusError.ErrStatus.Message) } else if err != nil { panic(err.Error()) } else { fmt.Printf("Found pod %s in namespace %s\n", pod, namespace) } time.Sleep(1 * time.Second) } }, }
RootCmd represents the base command when called without any subcommands
Functions ¶
Types ¶
type PodLoggingController ¶
type PodLoggingController struct {
// contains filtered or unexported fields
}
PodLoggingController logs the name and namespace of pods that are added, deleted, or updated
func NewPodLoggingController ¶
func NewPodLoggingController(informerFactory informers.SharedInformerFactory) *PodLoggingController
NewPodLoggingController creates a PodLoggingController
func (*PodLoggingController) Run ¶
func (c *PodLoggingController) Run(stopCh chan struct{}) error
Run starts shared informers and waits for the shared informer cache to synchronize.
Click to show internal directories.
Click to hide internal directories.