func getNEGStatus()

in projects/k8s-hybrid-neg-controller/pkg/reconciler/endpointslice.go [147:169]


func getNEGStatus(logger logr.Logger, service *corev1.Service) (*annotation.NEGStatus, error) {
	hybridNEGConfigAnnotationValue, serviceHasHybridNEGConfigAnnotation := service.Annotations[annotation.HybridNEGConfigKey]
	hybridNEGStatusAnnotationValue, serviceHasHybridNEGStatusAnnotation := service.Annotations[annotation.HybridNEGStatusKey]
	if !serviceHasHybridNEGConfigAnnotation && !serviceHasHybridNEGStatusAnnotation {
		logger.V(4).Info("Service does not have the hybrid NEG config or status annotations, skipping reconcile")
		return nil, nil
	}
	negConfig := &annotation.NEGConfig{}
	if serviceHasHybridNEGConfigAnnotation {
		if err := json.Unmarshal([]byte(hybridNEGConfigAnnotationValue), negConfig); err != nil {
			return nil, reconcile.TerminalError(fmt.Errorf("could not unmarshall NEG config annotation value [%s]:%w", hybridNEGConfigAnnotationValue, err))
		}
	}
	if serviceHasHybridNEGConfigAnnotation && len(negConfig.ExposedPorts) > 0 && !serviceHasHybridNEGStatusAnnotation {
		// The status annotation may not have been created yet, requeue to try again.
		return nil, fmt.Errorf("%w, requeueing", errNoStatusAnnotation)
	}
	negStatus := &annotation.NEGStatus{}
	if err := json.Unmarshal([]byte(hybridNEGStatusAnnotationValue), negStatus); err != nil {
		return nil, reconcile.TerminalError(fmt.Errorf("could not unmarshall NEG status annotation value [%s]:%w", hybridNEGStatusAnnotationValue, err))
	}
	return negStatus, nil
}