Skip to content

Commit 660aefe

Browse files
authored
provider: expose lb ip address (#381)
* use NodePort to support GCP. GCP provides a new IP address for every ingress * provider/cluster/kube: configure ingress behavior * provider/cluster/kube: expose lb hosts
1 parent 321a48f commit 660aefe

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

provider/cluster/kube/builder.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
akashv1 "github.com/ovrclk/akash/pkg/apis/akash.network/v1"
1111
"github.com/ovrclk/akash/types"
12-
"github.com/satori/go.uuid"
12+
uuid "github.com/satori/go.uuid"
1313
appsv1 "k8s.io/api/apps/v1"
1414
corev1 "k8s.io/api/core/v1"
1515
extv1 "k8s.io/api/extensions/v1beta1"
@@ -183,6 +183,9 @@ func (b *serviceBuilder) create() (*corev1.Service, error) {
183183
Labels: b.labels(),
184184
},
185185
Spec: corev1.ServiceSpec{
186+
// use NodePort to support GCP. GCP provides a new IP address for every ingress
187+
// and requires the service type to be either NodePort or LoadBalancer
188+
Type: config.DeploymentServiceType,
186189
Selector: b.labels(),
187190
Ports: b.ports(),
188191
},
@@ -216,7 +219,9 @@ type ingressBuilder struct {
216219

217220
func newIngressBuilder(host string, lid types.LeaseID, group *types.ManifestGroup, service *types.ManifestService, expose *types.ManifestServiceExpose) *ingressBuilder {
218221
uid := uuid.NewV4()
219-
expose.Hosts = append(expose.Hosts, fmt.Sprintf("%v.%s.%v", service.Name, uid, host))
222+
if config.DeploymentIngressStaticHosts {
223+
expose.Hosts = append(expose.Hosts, fmt.Sprintf("%v.%s.%v", service.Name, uid, host))
224+
}
220225
return &ingressBuilder{
221226
deploymentBuilder: deploymentBuilder{builder: builder{lid, group}, service: service},
222227
expose: expose,

provider/cluster/kube/client.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,22 @@ func (c *client) LeaseStatus(lid types.LeaseID) (*types.LeaseStatusResponse, err
225225
for _, ing := range ingress.Items {
226226
service := serviceStatus[ing.Name]
227227
hosts := []string{}
228+
228229
for _, rule := range ing.Spec.Rules {
229230
hosts = append(hosts, rule.Host)
230231
}
232+
233+
if config.DeploymentIngressExposeLBHosts {
234+
for _, lbing := range ing.Status.LoadBalancer.Ingress {
235+
if val := lbing.IP; val != "" {
236+
hosts = append(hosts, val)
237+
}
238+
if val := lbing.Hostname; val != "" {
239+
hosts = append(hosts, val)
240+
}
241+
}
242+
}
243+
231244
service.URIs = hosts
232245
}
233246
response := &types.LeaseStatusResponse{}

provider/cluster/kube/config.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package kube
2+
3+
import (
4+
"github.com/caarlos0/env"
5+
corev1 "k8s.io/api/core/v1"
6+
)
7+
8+
type config_ struct {
9+
10+
// gcp: NodePort
11+
// others: ClusterIP
12+
DeploymentServiceType corev1.ServiceType `env:"AKASH_DEPLOYMENT_SERVICE_TYPE" envDefault:"NodePort"`
13+
14+
// gcp: False
15+
// others: true
16+
DeploymentIngressStaticHosts bool `env:"AKASH_DEPLOYMENT_INGRESS_STATIC_HOSTS" envDefault:"false"`
17+
18+
DeploymentIngressExposeLBHosts bool `env:"AKASH_DEPLOYMENT_INGRESS_EXPOSE_LB_HOSTS" envDefault:"true"`
19+
}
20+
21+
var config = config_{}
22+
23+
func init() {
24+
if err := env.Parse(&config); err != nil {
25+
panic(err)
26+
}
27+
}

0 commit comments

Comments
 (0)