-
Notifications
You must be signed in to change notification settings - Fork 0
/
aws.go
69 lines (61 loc) · 1.64 KB
/
aws.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
68
69
package cloudprovider
import (
"strconv"
"github.com/luizalabs/teresa/pkg/server/service"
"github.com/luizalabs/teresa/pkg/server/spec"
"github.com/luizalabs/teresa/pkg/server/teresa_errors"
)
const (
awsSSLCertAnnotation = "service.beta.kubernetes.io/aws-load-balancer-ssl-cert"
awsSSLPortsAnnotation = "service.beta.kubernetes.io/aws-load-balancer-ssl-ports"
)
type awsOperations struct {
k8s K8sOperations
}
func (ops *awsOperations) CreateOrUpdateSSL(appName, cert string, port int) error {
hasIngress, err := ops.k8s.HasIngress(appName, appName)
if err != nil {
return err
}
if hasIngress {
return ErrNotImplementedOnIngress
}
anMap := map[string]string{
awsSSLCertAnnotation: cert,
awsSSLPortsAnnotation: strconv.Itoa(port),
}
if err := ops.k8s.SetServiceAnnotations(appName, appName, anMap); err != nil {
return teresa_errors.NewInternalServerError(err)
}
return nil
}
func (ops *awsOperations) CreateOrUpdateStaticIp(appName, addressName string) error {
return ErrNotImplemented
}
func (ops *awsOperations) SSLInfo(appName string) (*service.SSLInfo, error) {
var port int
an, err := ops.k8s.ServiceAnnotations(appName, appName)
if err != nil {
if ops.k8s.IsNotFound(err) {
return nil, ErrServiceNotFound
}
return nil, teresa_errors.NewInternalServerError(err)
}
sslAn, ok := an[awsSSLPortsAnnotation]
if ok {
port, err = strconv.Atoi(sslAn)
if err != nil {
return nil, teresa_errors.NewInternalServerError(err)
}
}
info := &service.SSLInfo{
Cert: an[awsSSLCertAnnotation],
ServicePort: &spec.ServicePort{
Port: port,
},
}
return info, nil
}
func (ops *awsOperations) Name() string {
return "aws"
}