• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tensorchord / openmodelz / 6300921844

25 Sep 2023 01:45PM UTC coverage: 27.15% (-0.02%) from 27.165%
6300921844

Pull #180

github

xieydd
Chore: Update agent token scheme, add cluster name

Signed-off-by: xieydd <xieydd@gmail.com>
Pull Request #180: Chore: Update agent token scheme, add cluster name

6 of 6 new or added lines in 3 files covered. (100.0%)

982 of 3617 relevant lines covered (27.15%)

1.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/agent/pkg/server/server_init_modelz_cloud.go
1
package server
2

3
import (
4
        "context"
5

6
        "github.com/pkg/errors"
7
        "github.com/sirupsen/logrus"
8
        "github.com/tensorchord/openmodelz/agent/api/types"
9
        "github.com/tensorchord/openmodelz/agent/client"
10
)
11

12
func (s *Server) initModelZCloud(url, token, region string) error {
×
13
        cluster := types.ManagedCluster{
×
14
                Region: region,
×
15
        }
×
16

×
17
        cli, err := client.NewClientWithOpts(
×
18
                client.WithHost(url))
×
19
        if err != nil {
×
20
                return errors.Wrap(err, "failed to create modelz cloud client")
×
21
        }
×
22
        s.modelzCloudClient = cli
×
23

×
24
        err = s.runtime.GetClusterInfo(&cluster)
×
25
        if err != nil {
×
26
                return errors.Wrap(err, "failed to get managed cluster info")
×
27
        }
×
28

29
        apiServerReady := make(chan struct{})
×
30
        go func() {
×
31
                if err := s.modelzCloudClient.WaitForAPIServerReady(); err != nil {
×
32
                        logrus.Fatalf("failed to wait for apiserver ready: %v", err)
×
33
                }
×
34
                close(apiServerReady)
×
35
        }()
36

37
        cluster.Status = types.ClusterStatusInit
×
38
        // after init modelz cloud client, register agent
×
39
        err = cli.RegisterAgent(context.Background(), token, &cluster)
×
40
        if err != nil {
×
41
                return errors.Wrap(err, "failed to register agent to modelz cloud")
×
42
        }
×
43
        s.config.ModelZCloud.ID = cluster.ID
×
44
        s.config.ModelZCloud.TokenID = cluster.TokenID
×
45
        s.config.ModelZCloud.Name = cluster.Name
×
46

×
47
        apikeys, err := s.modelzCloudClient.GetAPIKeys(context.Background(), apiServerReady, s.config.ModelZCloud.AgentToken, s.config.ModelZCloud.ID)
×
48
        if err != nil {
×
49
                logrus.Errorf("failed to get apikeys: %v", err)
×
50
        }
×
51

52
        s.config.ModelZCloud.APIKeys = apikeys
×
53

×
54
        namespaces, err := s.modelzCloudClient.GetNamespaces(context.Background(), apiServerReady, s.config.ModelZCloud.AgentToken, s.config.ModelZCloud.ID)
×
55
        if err != nil {
×
56
                logrus.Errorf("failed to get namespaces: %v", err)
×
57
        }
×
58

59
        nss := []string{}
×
60
        for _, ns := range namespaces.Items {
×
61
                nss = append(nss, ns)
×
62
                err = s.runtime.NamespaceCreate(context.Background(), ns)
×
63
                if err != nil {
×
64
                        logrus.Errorf("failed to create namespace %s: %v", ns, err)
×
65
                        continue
×
66
                }
67
        }
68
        s.config.ModelZCloud.UserNamespaces = nss
×
69

×
70
        return nil
×
71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc