Skip to content

Commit

Permalink
Support updating system controller (#1144)
Browse files Browse the repository at this point in the history
* Support updating system controller

* Fix integration failure
  • Loading branch information
xxx7xxxx committed Dec 5, 2023
1 parent f894a76 commit 918d1bb
Show file tree
Hide file tree
Showing 26 changed files with 226 additions and 101 deletions.
4 changes: 2 additions & 2 deletions build/test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func TestEgctlCmd(t *testing.T) {
output, stderr, err := runCmd(cmd)
assert.NoError(err)
assert.Empty(stderr)
head := []string{"NAME", "ALIASES", "KIND", "ACTION"}
head := []string{"NAME", "ALIASES", "CATEGORY", "KIND", "ACTION"}
assert.True(matchTable(head, output))
assert.True(matchTable([]string{"member", "m,mem,members", "Member", "delete,get,describe"}, output))
assert.Contains(output, "create,apply,delete,get,describe")
Expand Down Expand Up @@ -628,7 +628,7 @@ func TestLogs(t *testing.T) {
// check if new logs are printed
yamlStr := `
kind: HTTPServer
name: test-egctl-logs
name: test-egctl-logs
port: 12345
rules:
- paths:
Expand Down
4 changes: 2 additions & 2 deletions cmd/client/commandv2/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ func APIResourcesCmd() *cobra.Command {
sort.Slice(r.Aliases, func(i, j int) bool {
return len(r.Aliases[i]) < len(r.Aliases[j])
})
tables = append(tables, []string{r.Name, strings.Join(r.Aliases, ","), r.Kind, action})
tables = append(tables, []string{r.Name, strings.Join(r.Aliases, ","), r.Category, r.Kind, action})
}
sort.Slice(tables, func(i, j int) bool {
return tables[i][0] < tables[j][0]
})

tables = append([][]string{{"NAME", "ALIASES", "KIND", "ACTION"}}, tables...)
tables = append([][]string{{"NAME", "ALIASES", "CATEGORY", "KIND", "ACTION"}}, tables...)
tables = append(tables, []string{cdk.Name, strings.Join(cdk.Aliases, ","), cdk.Kind, action})
tables = append(tables, []string{cd.Name, strings.Join(cd.Aliases, ","), cd.Kind, action})
tables = append(tables, []string{member.Name, strings.Join(member.Aliases, ","), member.Kind, "delete,get,describe"})
Expand Down
10 changes: 10 additions & 0 deletions pkg/api/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ func (s *Server) createObject(w http.ResponseWriter, r *http.Request) {
return
}

if spec.Categroy() == supervisor.CategorySystemController {
HandleAPIError(w, r, http.StatusConflict, fmt.Errorf("can't create system controller object"))
}

name := spec.Name()

s.Lock()
Expand All @@ -164,6 +168,12 @@ func (s *Server) deleteObject(w http.ResponseWriter, r *http.Request) {
defer s.Unlock()

spec := s._getObject(name)

if spec.Categroy() == supervisor.CategorySystemController {
HandleAPIError(w, r, http.StatusBadRequest, fmt.Errorf("can't delete system controller object"))
return
}

if spec == nil {
HandleAPIError(w, r, http.StatusNotFound, fmt.Errorf("not found"))
return
Expand Down
15 changes: 8 additions & 7 deletions pkg/api/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ import (
)

type APIResource struct {
Kind string
Name string
Aliases []string
Category string
Kind string
Name string
Aliases []string
}

// key is Kind name, now only contains api resource of object.
var objectApiResource = map[string]*APIResource{}
var objectAPIResource = map[string]*APIResource{}

func RegisterObject(r *APIResource) {
if r.Kind == "" {
Expand All @@ -39,16 +40,16 @@ func RegisterObject(r *APIResource) {
panic(fmt.Errorf("%v: empty name", r))
}

existedObject, existed := objectApiResource[r.Kind]
existedObject, existed := objectAPIResource[r.Kind]
if existed {
panic(fmt.Errorf("%v and %v got same kind: %s", r, existedObject, r.Kind))
}
objectApiResource[r.Kind] = r
objectAPIResource[r.Kind] = r
}

func ObjectAPIResources() []*APIResource {
resources := []*APIResource{}
for _, r := range objectApiResource {
for _, r := range objectAPIResource {
resources = append(resources, r)
}
return resources
Expand Down
7 changes: 4 additions & 3 deletions pkg/object/autocertmanager/autocertmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ var aliases = []string{
func init() {
supervisor.Register(&AutoCertManager{})
api.RegisterObject(&api.APIResource{
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: aliases,
Category: Category,
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: aliases,
})
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/object/consulserviceregistry/consulserviceregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ var aliases = []string{"consul", "consulserviceregistrys"}
func init() {
supervisor.Register(&ConsulServiceRegistry{})
egapi.RegisterObject(&egapi.APIResource{
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: aliases,
Category: Category,
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: aliases,
})
}

Expand Down
10 changes: 7 additions & 3 deletions pkg/object/easemonitormetrics/easemonitormetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ import (
)

const (
// Category is the category of EaseMonitorMetrics.
Category = supervisor.CategoryBusinessController

// Kind is EaseMonitorMetrics kind.
Kind = "EaseMonitorMetrics"
)
Expand All @@ -54,9 +57,10 @@ func init() {
}

api.RegisterObject(&api.APIResource{
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: aliases,
Category: Category,
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: aliases,
})
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/object/etcdserviceregistry/etcdserviceregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ var aliases = []string{"etcd"}
func init() {
supervisor.Register(&EtcdServiceRegistry{})
api.RegisterObject(&api.APIResource{
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: aliases,
Category: Category,
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: aliases,
})
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/object/eurekaserviceregistry/eurekaserviceregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ var aliases = []string{"eureka"}
func init() {
supervisor.Register(&EurekaServiceRegistry{})
api.RegisterObject(&api.APIResource{
Kind: Kind,
Name: name,
Aliases: aliases,
Category: Category,
Kind: Kind,
Name: name,
Aliases: aliases,
})
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/object/function/faascontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ var aliases = []string{
func init() {
supervisor.Register(&FaasController{})
api.RegisterObject(&api.APIResource{
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: aliases,
Category: Category,
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: aliases,
})
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/object/globalfilter/globalfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ var aliases = []string{"globalfilters"}
func init() {
supervisor.Register(&GlobalFilter{})
api.RegisterObject(&api.APIResource{
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: aliases,
Category: Category,
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: aliases,
})
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/object/grpcserver/grpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ const (
func init() {
supervisor.Register(&GRPCServer{})
api.RegisterObject(&api.APIResource{
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: []string{"grpc"},
Category: Category,
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: []string{"grpc"},
})
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/object/httpserver/httpserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ const (
func init() {
supervisor.Register(&HTTPServer{})
api.RegisterObject(&api.APIResource{
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: []string{"httpservers", "hs"},
Category: Category,
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: []string{"httpservers", "hs"},
})
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/object/ingresscontroller/ingresscontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ const (
func init() {
supervisor.Register(&IngressController{})
api.RegisterObject(&api.APIResource{
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: []string{"ingresscontrollers", "ingress"},
Category: Category,
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: []string{"ingresscontrollers", "ingress"},
})
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/object/meshcontroller/meshcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ const (
func init() {
supervisor.Register(&MeshController{})
egapi.RegisterObject(&egapi.APIResource{
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: []string{"mesh", "meshcontrollers"},
Category: Category,
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: []string{"mesh", "meshcontrollers"},
})
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/object/mqttproxy/mqttproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ var _ supervisor.TrafficObject = (*MQTTProxy)(nil)
func init() {
supervisor.Register(&MQTTProxy{})
api.RegisterObject(&api.APIResource{
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: []string{"mqtt", "mp"},
Category: Category,
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: []string{"mqtt", "mp"},
})
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/object/nacosserviceregistry/nacosserviceregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ const (
func init() {
supervisor.Register(&NacosServiceRegistry{})
api.RegisterObject(&api.APIResource{
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: []string{"nacos"},
Category: Category,
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: []string{"nacos"},
})
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/object/pipeline/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ const (
func init() {
supervisor.Register(&Pipeline{})
api.RegisterObject(&api.APIResource{
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: []string{"pipelines", "pl"},
Category: Category,
Kind: Kind,
Name: strings.ToLower(Kind),
Aliases: []string{"pipelines", "pl"},
})
}

Expand Down
Loading

0 comments on commit 918d1bb

Please sign in to comment.