-
Notifications
You must be signed in to change notification settings - Fork 79
/
gce.go
67 lines (60 loc) · 1.6 KB
/
gce.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package cloudprovider
import (
"github.com/luizalabs/teresa/pkg/server/service"
"github.com/luizalabs/teresa/pkg/server/teresa_errors"
)
const (
gceSSLCertAnnotation = "ingress.gcp.kubernetes.io/pre-shared-cert"
gceStaticIPAnnotation = "kubernetes.io/ingress.global-static-ip-name"
)
type gceOperations struct {
k8s K8sOperations
}
func (ops *gceOperations) CreateOrUpdateSSL(appName, cert string, port int) error {
hasIngress, err := ops.k8s.HasIngress(appName, appName)
if err != nil {
return err
}
if !hasIngress {
return ErrIngressNotFound
}
anMap := map[string]string{
gceSSLCertAnnotation: cert,
}
if err := ops.k8s.SetIngressAnnotations(appName, appName, anMap); err != nil {
return teresa_errors.NewInternalServerError(err)
}
return nil
}
func (ops *gceOperations) CreateOrUpdateStaticIp(appName, addressName string) error {
hasIngress, err := ops.k8s.HasIngress(appName, appName)
if err != nil {
return err
}
if !hasIngress {
return ErrIngressNotFound
}
anMap := map[string]string{
gceStaticIPAnnotation: addressName,
}
if err := ops.k8s.SetIngressAnnotations(appName, appName, anMap); err != nil {
return teresa_errors.NewInternalServerError(err)
}
return nil
}
func (ops *gceOperations) SSLInfo(appName string) (*service.SSLInfo, error) {
an, err := ops.k8s.IngressAnnotations(appName, appName)
if err != nil {
if ops.k8s.IsNotFound(err) {
return nil, ErrIngressNotFound
}
return nil, teresa_errors.NewInternalServerError(err)
}
info := &service.SSLInfo{
Cert: an[gceSSLCertAnnotation],
}
return info, nil
}
func (ops *gceOperations) Name() string {
return "gce"
}