Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: feature discovery enablement #168

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions gateway/rest/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"encoding/json"
"fmt"
"io"
"io/ioutil"

Check failure on line 10 in gateway/rest/router.go

View workflow job for this annotation

GitHub Actions / lint

SA1019: "io/ioutil" has been deprecated since Go 1.19: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code. See the specific function documentation for details. (staticcheck)
"net/http"
"net/http/httputil"
"net/url"
Expand Down Expand Up @@ -43,6 +44,8 @@
"github.com/akash-network/provider/gateway/utils"
pmanifest "github.com/akash-network/provider/manifest"
ipoptypes "github.com/akash-network/provider/operator/ipoperator/types"

v1 "github.com/akash-network/akash-api/go/inventory/v1"
)

type CtxAuthKey string
Expand Down Expand Up @@ -107,6 +110,12 @@
createStatusHandler(log, pclient, addr)).
Methods("GET")

// GET /features
// provider features endpoint does not require authentication
router.HandleFunc("/features",
createFeaturesHandler(log, pclient, addr)).
Methods("GET")

vrouter := router.NewRoute().Subrouter()
vrouter.Use(requireOwner())

Expand Down Expand Up @@ -524,6 +533,52 @@
}
}

func createFeaturesHandler(log log.Logger, sclient provider.StatusClient, providerAddr sdk.Address) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {

// URLs slice and use in range allows execution in both dev and prod
urls := []string{
"http://inventory-operator.akash-services.svc.cluster.local:8081/getClusterState",
"http://localhost:8081/getClusterState",
}

var resp *http.Response
var err error
for _, url := range urls {
resp, err = http.Get(url)
if err != nil {
fmt.Printf("Failed to get '%s': %v\n", url, err)
continue
}
defer resp.Body.Close()
break
}

if err != nil {
fmt.Printf("All attempts failed: %v\n", err)
return
}

defer resp.Body.Close()

bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
}

var clusterState v1.Cluster
err = json.Unmarshal(bodyBytes, &clusterState)
if err != nil {
fmt.Println(err)
}

fmt.Println("clusterState: ", clusterState)

writeJSON(log, w, clusterState)

}
}

func validateHandler(log log.Logger, cl provider.ValidateClient) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
data, err := io.ReadAll(req.Body)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/akash-network/provider
go 1.21

require (
github.com/akash-network/akash-api v0.0.33
github.com/akash-network/akash-api v0.0.36-rc0
github.com/akash-network/node v0.28.2
github.com/avast/retry-go/v4 v4.5.0
github.com/boz/go-lifecycle v0.1.1
Expand All @@ -30,6 +30,7 @@ require (
github.com/tendermint/tendermint v0.34.27
go.uber.org/zap v1.24.0
golang.org/x/sync v0.3.0
google.golang.org/grpc v1.57.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.26.1
k8s.io/apimachinery v0.26.1
Expand Down Expand Up @@ -248,7 +249,6 @@ require (
google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230706204954-ccb25ca9f130 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230720185612-659f7aaaa771 // indirect
google.golang.org/grpc v1.57.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia
github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM=
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
github.com/akash-network/akash-api v0.0.33 h1:SvOht1F3BDz3el8XKC7lbRzc6D++kERs5wFRisMWzCY=
github.com/akash-network/akash-api v0.0.33/go.mod h1:pW5NnJNhxynCOUGEcgxa338GSU2qzMkpn3MMYcAY6O4=
github.com/akash-network/akash-api v0.0.36-rc0 h1:Mp+T5ZkbF8eRZXztLrnVdYxAsLmRHfKsP9NrmSna9PQ=
github.com/akash-network/akash-api v0.0.36-rc0/go.mod h1:pW5NnJNhxynCOUGEcgxa338GSU2qzMkpn3MMYcAY6O4=
github.com/akash-network/cometbft v0.34.27-akash h1:V1dApDOr8Ee7BJzYyQ7Z9VBtrAul4+baMeA6C49dje0=
github.com/akash-network/cometbft v0.34.27-akash/go.mod h1:BcCbhKv7ieM0KEddnYXvQZR+pZykTKReJJYf7YC7qhw=
github.com/akash-network/ledger-go v0.14.3 h1:LCEFkTfgGA2xFMN2CtiKvXKE7dh0QSM77PJHCpSkaAo=
Expand Down
25 changes: 25 additions & 0 deletions operator/inventory/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"net"
"net/http"
"sync"
Expand Down Expand Up @@ -94,6 +95,30 @@ func Cmd() *cobra.Command {
}
storage = append(storage, st)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

// Channel to receive error messages from the goroutine
errChan := make(chan error, 1)

// Start FeatureDiscovery in a separate goroutine
go func() {
errChan <- FeatureDiscovery(ctx)
}()

// ... other code ...

select {
case err := <-errChan:
// Handle error from FeatureDiscovery
// You might log the error, or take corrective action
log.Printf("FeatureDiscovery encountered an error: %v", err)
case <-cmd.Context().Done():
// Handle the case where the main command is stopped
// Cancel the context used by FeatureDiscovery
cancel()
}

if st, err = NewRancher(cmd.Context()); err != nil {
return err
}
Expand Down
Loading
Loading