-
Notifications
You must be signed in to change notification settings - Fork 22
/
current.go
40 lines (32 loc) · 1.05 KB
/
current.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package service
import (
"context"
"github.com/giantswarm/microerror"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/giantswarm/aws-operator/v14/service/controller/key"
)
func (r *Resource) GetCurrentState(ctx context.Context, obj interface{}) (interface{}, error) {
cr, err := key.ToCluster(ctx, obj)
if err != nil {
return nil, microerror.Mask(err)
}
r.logger.Debugf(ctx, "looking for the service in the Kubernetes API")
namespace := key.ClusterNamespace(cr)
// Lookup the current state of the service.
var service *corev1.Service
{
manifest, err := r.k8sClient.CoreV1().Services(namespace).Get(ctx, masterServiceName, metav1.GetOptions{})
if apierrors.IsNotFound(err) {
r.logger.Debugf(ctx, "did not find the service in the Kubernetes API")
// fall through
} else if err != nil {
return nil, microerror.Mask(err)
} else {
r.logger.Debugf(ctx, "found the service in the Kubernetes API")
service = manifest
}
}
return service, nil
}