Skip to content

Commit

Permalink
Add comments for check-gke-ingress rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixiansong committed May 18, 2023
1 parent 4cc3ec7 commit 1c4bfa6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/check-gke-ingress/app/ingress/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
feconfigclient "k8s.io/ingress-gce/pkg/frontendconfig/client/clientset/versioned"
)

// CheckServiceExistence checks whether a service exists.
func CheckServiceExistence(namespace, name string, client clientset.Interface) (*corev1.Service, string, string) {
svc, err := client.CoreV1().Services(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
Expand All @@ -45,6 +46,11 @@ func CheckServiceExistence(namespace, name string, client clientset.Interface) (
return svc, report.Passed, fmt.Sprintf("Service %s/%s found", namespace, name)
}

// CheckBackendConfigAnnotation checks the BackendConfig annotation of a
// service for:
//
// whether the annotation is a valid BackendConfig json object.
// whether the annotation has `default` or `ports` field.
func CheckBackendConfigAnnotation(svc *corev1.Service) (*annotations.BackendConfigs, string, string) {
val, ok := getBackendConfigAnnotation(svc)
if !ok {
Expand All @@ -60,6 +66,7 @@ func CheckBackendConfigAnnotation(svc *corev1.Service) (*annotations.BackendConf
return beConfigs, report.Passed, fmt.Sprintf("BackendConfig annotation is valid in service %s/%s", svc.Namespace, svc.Name)
}

// CheckBackendConfigExistence checks whether a BackendConfig exists.
func CheckBackendConfigExistence(ns string, beConfigName string, svcName string, client beconfigclient.Interface) (*beconfigv1.BackendConfig, string, string) {
beConfig, err := client.CloudV1().BackendConfigs(ns).Get(context.TODO(), beConfigName, metav1.GetOptions{})
if err != nil {
Expand All @@ -71,6 +78,8 @@ func CheckBackendConfigExistence(ns string, beConfigName string, svcName string,
return beConfig, report.Passed, fmt.Sprintf("BackendConfig %s/%s in service %s/%s found", ns, beConfigName, ns, svcName)
}

// CheckHealthCheckTimeout checks whether timeout time is smaller than check
// interval in backendconfig health check configuration.
func CheckHealthCheckTimeout(beConfig *beconfigv1.BackendConfig, svcName string) (string, string) {
if beConfig.Spec.HealthCheck == nil {
return report.Skipped, fmt.Sprintf("BackendConfig %s/%s in service %s/%s does not have healthcheck specified", beConfig.Namespace, beConfig.Name, beConfig.Namespace, svcName)
Expand All @@ -84,6 +93,7 @@ func CheckHealthCheckTimeout(beConfig *beconfigv1.BackendConfig, svcName string)
return report.Passed, fmt.Sprintf("BackendConfig %s/%s in service %s/%s healthcheck configuration is valid", beConfig.Namespace, beConfig.Name, beConfig.Namespace, svcName)
}

// CheckIngressRule checks whether an ingress rule has the http field.
func CheckIngressRule(ingressRule *networkingv1.IngressRule) (*networkingv1.HTTPIngressRuleValue, string, string) {
if ingressRule.HTTP == nil {
return nil, report.Failed, "IngressRule has no field `http`"
Expand Down

0 comments on commit 1c4bfa6

Please sign in to comment.