forked from giantswarm/aws-operator
/
current.go
40 lines (32 loc) · 1.11 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"
apiv1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
apismetav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/giantswarm/aws-operator/service/awsconfig/v3/key"
)
func (r *Resource) GetCurrentState(ctx context.Context, obj interface{}) (interface{}, error) {
customObject, err := key.ToCustomObject(obj)
if err != nil {
return nil, microerror.Mask(err)
}
r.logger.LogCtx(ctx, "debug", "looking for the master service in the Kubernetes API")
namespace := key.ClusterNamespace(customObject)
// Lookup the current state of the service.
var service *apiv1.Service
{
manifest, err := r.k8sClient.CoreV1().Services(namespace).Get(masterServiceName, apismetav1.GetOptions{})
if apierrors.IsNotFound(err) {
r.logger.LogCtx(ctx, "debug", "did not find the master service in the Kubernetes API")
// fall through
} else if err != nil {
return nil, microerror.Mask(err)
} else {
r.logger.LogCtx(ctx, "debug", "found the master service in the Kubernetes API")
service = manifest
}
}
return service, nil
}