in appconfigmgrv2/controllers/services.go [65:96]
func (r *AppEnvConfigTemplateV2Reconciler) reconcileService(
ctx context.Context,
s *corev1.Service,
) error {
found := &corev1.Service{}
err := r.Get(ctx, types.NamespacedName{Name: s.Name, Namespace: s.Namespace}, found)
if err != nil && errors.IsNotFound(err) {
log.Info("Creating", "resource", "services", "namespace", s.Namespace, "name", s.Name)
err = r.Create(ctx, s)
return err
} else if err != nil {
return err
}
if !reflect.DeepEqual(s.Spec, found.Spec) {
// ClusterIP is assigned after creation when it is not originally set
// so we will preserve the value.
s.Spec.ClusterIP = found.Spec.ClusterIP
if s.Spec.Type != corev1.ServiceTypeClusterIP {
for i := range s.Spec.Ports {
s.Spec.Ports[i].NodePort = found.Spec.Ports[i].NodePort
}
}
found.Spec = s.Spec
log.Info("Updating", "resource", "services", "namespace", s.Namespace, "name", s.Name)
if err := r.Update(ctx, found); err != nil {
return err
}
}
return nil
}