How to use checkNamespace method of main Package

Best Syzkaller code snippet using main.checkNamespace

crd.go

Source:crd.go Github

copy

Full Screen

...21 "github.com/kuberhealthy/kuberhealthy/v2/pkg/khstatecrd"22)23// setCheckStateResource puts a check state's state into the specified CRD resource. It sets the AuthoritativePod24// to the server's hostname and sets the LastUpdate time to now.25func setCheckStateResource(checkName string, checkNamespace string, state health.WorkloadDetails) error {26 name := sanitizeResourceName(checkName)27 // we must fetch the existing state to use the current resource version28 // int found within29 existingState, err := khStateClient.Get(metav1.GetOptions{}, stateCRDResource, name, checkNamespace)30 if err != nil {31 return errors.New("Error retrieving CRD for: " + name + " " + err.Error())32 }33 resourceVersion := existingState.GetResourceVersion()34 // set the pod name that wrote the khstate35 state.AuthoritativePod = podHostname36 state.LastRun = time.Now() // set the time the khstate was last37 khState := khstatecrd.NewKuberhealthyState(name, state)38 khState.SetResourceVersion(resourceVersion)39 // TODO - if "try again" message found in error, then try again40 log.Debugln(checkNamespace, checkName, "writing khstate with ok:", state.OK, "and errors:", state.Errors, "at last run:", state.LastRun)41 _, err = khStateClient.Update(&khState, stateCRDResource, name, checkNamespace)42 return err43}44// sanitizeResourceName cleans up the check names for use in CRDs.45// DNS-1123 subdomains must consist of lower case alphanumeric characters, '-'46// or '.', and must start and end with an alphanumeric character (e.g.47// 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?48// (\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')49func sanitizeResourceName(c string) string {50 // the name we pass to the CRD must be lowercase51 nameLower := strings.ToLower(c)52 return strings.Replace(nameLower, " ", "-", -1)53}54// ensureStateResourceExists checks for the existence of the specified resource and creates it if it does not exist55func ensureStateResourceExists(checkName string, checkNamespace string, workload health.KHWorkload) error {56 name := sanitizeResourceName(checkName)57 log.Debugln("Checking existence of custom resource:", name)58 state, err := khStateClient.Get(metav1.GetOptions{}, stateCRDResource, name, checkNamespace)59 if err != nil {60 if k8sErrors.IsNotFound(err) || strings.Contains(err.Error(), "not found") {61 log.Infoln("Custom resource not found, creating resource:", name, " - ", err)62 initialDetails := health.NewWorkloadDetails(workload)63 initialState := khstatecrd.NewKuberhealthyState(name, initialDetails)64 _, err := khStateClient.Create(&initialState, stateCRDResource, checkNamespace)65 if err != nil {66 return errors.New("Error creating custom resource: " + name + ": " + err.Error())67 }68 } else {69 return err70 }71 }72 if state.Spec.Errors != nil {73 log.Debugln("khstate custom resource found:", name)74 }75 return nil76}77// getCheckState retrieves the check values from the kuberhealthy khstate78// custom resource...

Full Screen

Full Screen

main.go

Source:main.go Github

copy

Full Screen

...40 log.Fatalf("The data doesent match the struct %v", err)41 }42 podName := falcoEvent.OutputFields.K8SPodName43 namespace := falcoEvent.OutputFields.K8SNsName44 var checkNamespace bool45 if allowList {46 checkNamespace = event.CheckAllowNamespace(namespace, allowNamespaces)47 } else {48 checkNamespace = event.CheckBlockNamespace(namespace, blockNamespaces)49 }50 if !checkNamespace {51 // TODO, we should add what namespace that blockNamespace output for easy debug52 log.Printf("Not deleting pod: %v, in namespace: %v", podName, namespace)53 os.Exit(0)54 }55 kubeClient, err := poddelete.SetupKubeClient(false)56 if err != nil {57 log.Fatalf("Unable to create in-cluster config: %v", err)58 }59 podProtected, err := kubeClient.CheckPodAnnotation(ctx, namespace, podName)60 if err != nil {61 log.Fatal("Unable to get pod annotation: ", err)62 }63 if podProtected {64 log.Printf("Not deleting pod: %v, in namespace: %v due to it got the annotation falco.org/protected: %v", namespace, podName, podProtected)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful