Skip to content

Commit

Permalink
fix(node): Insert endpoints in the deployment groups for each service…
Browse files Browse the repository at this point in the history
… the manifest declares that results in NodePort in kubernetes
  • Loading branch information
hydrogen18 committed Nov 26, 2020
1 parent 12b3f61 commit 116eaba
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
23 changes: 23 additions & 0 deletions sdl/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sort"

"github.com/ovrclk/akash/manifest"
providerUtil "github.com/ovrclk/akash/provider/cluster/util"
"github.com/ovrclk/akash/types"
dtypes "github.com/ovrclk/akash/x/deployment/types"
)
Expand Down Expand Up @@ -117,6 +118,28 @@ func (sdl *v2) DeploymentGroups() ([]*dtypes.GroupSpec, error) {
Count: svcdepl.Count,
}

endpointCount := 0
for _, expose := range sdl.Services[svcdepl.Profile].Expose {
for _, to := range expose.To {
proto, err := manifest.ParseServiceProtocol(expose.Proto)
if err != nil {
return nil, err
}
v := manifest.ServiceExpose{
Port: expose.Port,
ExternalPort: expose.As,
Proto: proto,
Service: to.Service,
Global: to.Global,
Hosts: expose.Accept.Items,
}
if !providerUtil.ShouldExpose(v) {
endpointCount++
}
}
}

resources.Resources.Endpoints = make([]types.Endpoint, endpointCount)
group.Resources = append(group.Resources, resources)

// TODO: Make a parameter to configure the duration of orders being bid on
Expand Down
33 changes: 33 additions & 0 deletions sdl/v2_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sdl

import (
"github.com/ovrclk/akash/validation"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -60,6 +61,37 @@ func TestV2Parse_Deployments(t *testing.T) {
require.NotEqual(t, sha1, sha3)
}

func Test_V2_Cross_Validates(t *testing.T) {
sdl2, err := ReadFile("../x/deployment/testdata/deployment-v2.yaml")
require.NoError(t, err)
dgroups, err := sdl2.DeploymentGroups()
require.NoError(t, err)
manifest, err := sdl2.Manifest()
require.NoError(t, err)

// This is a single document producing both the manifest & deployment groups
// These should always agree with each other. If this test fails at least one of the
// following is ture
// 1. Cross validation logic is wrong
// 2. The DeploymentGroups() & Manifest() code do not agree with one another
err = validation.ValidateManifestWithGroupSpecs(&manifest, dgroups)
require.NoError(t, err)

// Repeat the same test with another file
sdl2, err = ReadFile("./_testdata/simple.yaml")
require.NoError(t, err)
dgroups, err = sdl2.DeploymentGroups()
require.NoError(t, err)
manifest, err = sdl2.Manifest()
require.NoError(t, err)

// This is a single document producing both the manifest & deployment groups
// These should always agree with each other
err = validation.ValidateManifestWithGroupSpecs(&manifest, dgroups)
require.NoError(t, err)

}

func Test_v1_Parse_simple(t *testing.T) {
sdl, err := ReadFile("./_testdata/simple.yaml")
require.NoError(t, err)
Expand Down Expand Up @@ -90,6 +122,7 @@ func Test_v1_Parse_simple(t *testing.T) {
Storage: &atypes.Storage{
Quantity: atypes.NewResourceValue(randStorage),
},
Endpoints: make([]atypes.Endpoint, 1),
},
}, group.GetResources()[0])

Expand Down

0 comments on commit 116eaba

Please sign in to comment.