Skip to content

Commit

Permalink
APIGOV-28713 - updates for agent version and dataplaneType (#828)
Browse files Browse the repository at this point in the history
* regenerate api server resources

* cleanup for removed resources

* update dataplane if type not equal to what it should be

* update component def

* remove unified catalog scripts

* APIGOV-28713 - update test

* fix test

* APIGOV-28713 - update template

* code review comment
  • Loading branch information
jcollins-axway authored Sep 11, 2024
1 parent 330dd83 commit 9bb92cd
Show file tree
Hide file tree
Showing 76 changed files with 356 additions and 4,641 deletions.
4 changes: 0 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ test-sonar: dep
apiserver-generate: # generate api server resources, prod by default. ex: make apiserver-generate protocol=https host=apicentral.axway.com port=443
docker run --rm -v $(shell pwd)/scripts/apiserver:/codegen/scripts -v $(shell pwd)/pkg/apic/apiserver:/codegen/output -e PROTOCOL='$(protocol)' -e HOST='$(host)' -e PORT='$(port)' -e USERID=$(shell id -u) -e GROUPID=$(shell id -g) -w /codegen/scripts --entrypoint ./apiserver_generate.sh ampc-beano-docker-release-phx.artifactory-phx.ecd.axway.int/base-images/beano-alpine-codegen:latest

unifiedcatalog-generate: ## generate unified catalog resources
./scripts/unifiedcatalog/unifiedcatalog_generate.sh


PROTOFILES := $(shell find $(WORKSPACE)/proto -type f -name '*.proto')
PROTOTARGETS := $(PROTOFILES:.proto=.pb.go)

Expand Down
21 changes: 9 additions & 12 deletions pkg/agent/resource/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,26 +312,23 @@ func (a *agentResourceManager) checkAgentResource() (*v1.ResourceInstance, error
var agentRes v1.Interface
logger := a.logger.WithField("scope", a.agentResource.Metadata.Scope).WithField("kind", a.agentResource.Kind).WithField("name", a.agentResource.Name)

update := false
currDataplaneType := apic.Unidentified.String()
if a.agentResource.Kind == management.DiscoveryAgentGVK().Kind {
da := management.NewDiscoveryAgent("", "")
da.FromInstance(a.agentResource)
if da.Spec.DataplaneType == "" {
da.Spec.DataplaneType = config.AgentDataPlaneType
agentRes = da
update = true
}
currDataplaneType = da.Spec.DataplaneType
da.Spec.DataplaneType = config.AgentDataPlaneType
agentRes = da
} else if a.agentResource.Kind == management.TraceabilityAgentGVK().Kind {
ta := management.NewTraceabilityAgent("", "")
ta.FromInstance(a.agentResource)
if ta.Spec.DataplaneType == "" {
ta.Spec.DataplaneType = config.AgentDataPlaneType
agentRes = ta
update = true
}
currDataplaneType = ta.Spec.DataplaneType
ta.Spec.DataplaneType = config.AgentDataPlaneType
agentRes = ta
}

if !update {
// nothing to update
if currDataplaneType == config.AgentDataPlaneType {
return a.agentResource, nil
}

Expand Down
48 changes: 24 additions & 24 deletions pkg/apic/apiserver/clients/api/v1/fake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ import (
func TestFakeUnscoped(t *testing.T) {
cb, err := v1.NewFakeClient(&apiv1.ResourceInstance{
ResourceMeta: apiv1.ResourceMeta{
GroupVersionKind: management.K8SClusterGVK(),
Name: "muhName",
GroupVersionKind: management.EnvironmentGVK(),
Name: "environment",
},
Spec: map[string]interface{}{},
})
if err != nil {
t.Fatal("Failed due to: ", err)
}

k8sClient, err := cb.ForKind(management.K8SClusterGVK())
envClient, err := cb.ForKind(management.EnvironmentGVK())
if err != nil {
t.Fatal("Failed due to: ", err)
}
k8s, err := k8sClient.Get("muhName")
k8s, err := envClient.Get("environment")
if err != nil {
t.Fatal("Failed due to: ", err)
}
Expand All @@ -38,35 +38,35 @@ func TestFakeUnscoped(t *testing.T) {
func TestAddFakeUnscoped(t *testing.T) {
cb, err := v1.NewFakeClient(&apiv1.ResourceInstance{
ResourceMeta: apiv1.ResourceMeta{
GroupVersionKind: management.K8SClusterGVK(),
Name: "muhName",
GroupVersionKind: management.EnvironmentGVK(),
Name: "environment",
},
Spec: map[string]interface{}{},
})
if err != nil {
t.Fatal("Failed due to: ", err)
}

k8sClient, err := cb.ForKind(management.K8SClusterGVK())
envClient, err := cb.ForKind(management.EnvironmentGVK())
if err != nil {
t.Fatal("Failed due to: ", err)
}

_, err = k8sClient.Create(&apiv1.ResourceInstance{
_, err = envClient.Create(&apiv1.ResourceInstance{
ResourceMeta: apiv1.ResourceMeta{
GroupVersionKind: management.K8SClusterGVK(),
Name: "muhName",
GroupVersionKind: management.EnvironmentGVK(),
Name: "environment",
},
Spec: map[string]interface{}{},
})
if err == nil {
t.Fatal("Failed due to: expected error")
}

_, err = k8sClient.Create(&apiv1.ResourceInstance{
_, err = envClient.Create(&apiv1.ResourceInstance{
ResourceMeta: apiv1.ResourceMeta{
GroupVersionKind: management.K8SClusterGVK(),
Name: "muhSecondName",
GroupVersionKind: management.EnvironmentGVK(),
Name: "secondEnvironment",
},
Spec: map[string]interface{}{},
})
Expand All @@ -79,18 +79,18 @@ func TestFakeScoped(t *testing.T) {
cb, err := v1.NewFakeClient(
&apiv1.ResourceInstance{
ResourceMeta: apiv1.ResourceMeta{
GroupVersionKind: management.K8SClusterGVK(),
Name: "muhName",
GroupVersionKind: management.EnvironmentGVK(),
Name: "environment",
},
Spec: map[string]interface{}{},
},
&apiv1.ResourceInstance{
ResourceMeta: apiv1.ResourceMeta{
GroupVersionKind: management.K8SResourceGVK(),
Name: "muhResource",
GroupVersionKind: management.APIServiceGVK(),
Name: "apiService",
Metadata: apiv1.Metadata{
Scope: apiv1.MetadataScope{
Name: "muhName",
Name: "environment",
},
},
},
Expand All @@ -101,23 +101,23 @@ func TestFakeScoped(t *testing.T) {
t.Fatal("Failed due to: ", err)
}

noScope, err := cb.ForKind(management.K8SResourceGVK())
noScope, err := cb.ForKind(management.APIServiceGVK())
if err != nil {
t.Fatal("Failed due to: ", err)
}
_, err = noScope.WithScope("muhName").Get("muhResource")
_, err = noScope.WithScope("environment").Get("apiService")
if err != nil {
t.Fatal("Failed due to: ", err)
}

ri, err := noScope.WithScope("muhName").Update(
ri, err := noScope.WithScope("environment").Update(
&apiv1.ResourceInstance{
ResourceMeta: apiv1.ResourceMeta{
GroupVersionKind: management.K8SResourceGVK(),
Name: "muhResource",
GroupVersionKind: management.APIServiceGVK(),
Name: "apiService",
Metadata: apiv1.Metadata{
Scope: apiv1.MetadataScope{
Name: "muhName",
Name: "environment",
},
},
Attributes: map[string]string{"attribute": "value"},
Expand Down
8 changes: 4 additions & 4 deletions pkg/apic/apiserver/clients/api/v1/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ func TestRSQL(t *testing.T) {
},
{
"by reference",
Reference(management.ResourceDiscoveryGVK(), "my-rd-pods"),
`metadata.references.name==my-rd-pods;metadata.references.kind==ResourceDiscovery`,
Reference(management.APIServiceGVK(), "my-rd-pods"),
`metadata.references.name==my-rd-pods;metadata.references.kind==APIService`,
},
{
"by reference or attribute",
Or(AttrIn("a", "v1", "v2"), Reference(management.ResourceDiscoveryGVK(), "my-rd-svc")),
`(attributes.a=in=("v1","v2"),metadata.references.name==my-rd-svc;metadata.references.kind==ResourceDiscovery)`,
Or(AttrIn("a", "v1", "v2"), Reference(management.APIServiceGVK(), "my-rd-svc")),
`(attributes.a=in=("v1","v2"),metadata.references.name==my-rd-svc;metadata.references.kind==APIService)`,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
* This file is automatically generated
*/

package management
package definitions

import (
"fmt"

v1 "github.com/Axway/agent-sdk/pkg/apic/apiserver/clients/api/v1"
apiv1 "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/api/v1"
m "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/management/v1alpha1"
m "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/definitions/v1alpha1"
)

type MeshMergeFunc func(*m.Mesh, *m.Mesh) (*m.Mesh, error)
type ComponentMergeFunc func(*m.Component, *m.Component) (*m.Component, error)

// MeshMerge builds a merge option for an update operation
func MeshMerge(f MeshMergeFunc) v1.UpdateOption {
// ComponentMerge builds a merge option for an update operation
func ComponentMerge(f ComponentMergeFunc) v1.UpdateOption {
return v1.Merge(func(prev, new apiv1.Interface) (apiv1.Interface, error) {
p, n := &m.Mesh{}, &m.Mesh{}
p, n := &m.Component{}, &m.Component{}

switch t := prev.(type) {
case *m.Mesh:
case *m.Component:
p = t
case *apiv1.ResourceInstance:
err := p.FromInstance(t)
Expand All @@ -32,7 +32,7 @@ func MeshMerge(f MeshMergeFunc) v1.UpdateOption {
}

switch t := new.(type) {
case *m.Mesh:
case *m.Component:
n = t
case *apiv1.ResourceInstance:
err := n.FromInstance(t)
Expand All @@ -47,34 +47,34 @@ func MeshMerge(f MeshMergeFunc) v1.UpdateOption {
})
}

// MeshClient - rest client for Mesh resources that have a defined resource scope
type MeshClient struct {
// ComponentClient - rest client for Component resources that have a defined resource scope
type ComponentClient struct {
client v1.Scoped
}

// NewMeshClient - creates a client scoped to a particular resource
func NewMeshClient(c v1.Base) (*MeshClient, error) {
// NewComponentClient - creates a client scoped to a particular resource
func NewComponentClient(c v1.Base) (*ComponentClient, error) {

client, err := c.ForKind(m.MeshGVK())
client, err := c.ForKind(m.ComponentGVK())
if err != nil {
return nil, err
}

return &MeshClient{client}, nil
return &ComponentClient{client}, nil

}

// List - gets a list of resources
func (c *MeshClient) List(options ...v1.ListOptions) ([]*m.Mesh, error) {
func (c *ComponentClient) List(options ...v1.ListOptions) ([]*m.Component, error) {
riList, err := c.client.List(options...)
if err != nil {
return nil, err
}

result := make([]*m.Mesh, len(riList))
result := make([]*m.Component, len(riList))

for i := range riList {
result[i] = &m.Mesh{}
result[i] = &m.Component{}
err := result[i].FromInstance(riList[i])
if err != nil {
return nil, err
Expand All @@ -85,20 +85,20 @@ func (c *MeshClient) List(options ...v1.ListOptions) ([]*m.Mesh, error) {
}

// Get - gets a resource by name
func (c *MeshClient) Get(name string) (*m.Mesh, error) {
func (c *ComponentClient) Get(name string) (*m.Component, error) {
ri, err := c.client.Get(name)
if err != nil {
return nil, err
}

service := &m.Mesh{}
service := &m.Component{}
service.FromInstance(ri)

return service, nil
}

// Delete - deletes a resource
func (c *MeshClient) Delete(res *m.Mesh) error {
func (c *ComponentClient) Delete(res *m.Component) error {
ri, err := res.AsInstance()

if err != nil {
Expand All @@ -109,7 +109,7 @@ func (c *MeshClient) Delete(res *m.Mesh) error {
}

// Create - creates a resource
func (c *MeshClient) Create(res *m.Mesh, opts ...v1.CreateOption) (*m.Mesh, error) {
func (c *ComponentClient) Create(res *m.Component, opts ...v1.CreateOption) (*m.Component, error) {
ri, err := res.AsInstance()

if err != nil {
Expand All @@ -121,7 +121,7 @@ func (c *MeshClient) Create(res *m.Mesh, opts ...v1.CreateOption) (*m.Mesh, erro
return nil, err
}

created := &m.Mesh{}
created := &m.Component{}

err = created.FromInstance(cri)
if err != nil {
Expand All @@ -132,7 +132,7 @@ func (c *MeshClient) Create(res *m.Mesh, opts ...v1.CreateOption) (*m.Mesh, erro
}

// Update - updates a resource
func (c *MeshClient) Update(res *m.Mesh, opts ...v1.UpdateOption) (*m.Mesh, error) {
func (c *ComponentClient) Update(res *m.Component, opts ...v1.UpdateOption) (*m.Component, error) {
ri, err := res.AsInstance()
if err != nil {
return nil, err
Expand All @@ -142,7 +142,7 @@ func (c *MeshClient) Update(res *m.Mesh, opts ...v1.UpdateOption) (*m.Mesh, erro
return nil, err
}

updated := &m.Mesh{}
updated := &m.Component{}

// Updates the resource in place
err = updated.FromInstance(resource)
Expand Down
Loading

0 comments on commit 9bb92cd

Please sign in to comment.