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

feature/implement v2 rortypes and datacenter #291

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
25 changes: 13 additions & 12 deletions cmd/generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,23 @@ func main() {
// - cmd/tanzu/agent/tanzuservice/schemas/schemas_generated.go
//templateFile("cmd/tanzu/agent/tanzuservice/schemas/schemas_generated.go.tmpl", rordefs.GetResourcesByType(rordefs.ApiResourceTypeTanzuAgent))

templateFile("pkg/apicontracts/apiresourcecontracts/resource_models_generated.go.tmpl", rordefs.Resourcedefs)
templateFile("pkg/apicontracts/apiresourcecontracts/resource_models_methods_generated.go.tmpl", rordefs.Resourcedefs)

// Resource models
templateFile("pkg/rorresources/fromstruct.go.tmpl", rordefs.Resourcedefs)
templateFile("pkg/rorresources/resource.go.tmpl", rordefs.Resourcedefs)
templateFile("pkg/rorresources/rorkubernetes/k8s_test.go.tmpl", rordefs.Resourcedefs)
templateFile("pkg/rorresources/rorkubernetes/k8s.go.tmpl", rordefs.Resourcedefs)
templateFile("pkg/rorresources/rortypes/resource_interfaces.go.tmpl", rordefs.Resourcedefs)
templateFile("pkg/rorresources/rortypes/resource_models_methods.go.tmpl", rordefs.Resourcedefs)
// Resource models v1
templateFile("pkg/apicontracts/apiresourcecontracts/resource_models_generated.go.tmpl", rordefs.Resourcedefs.GetResourcesByVersion(rordefs.ApiVersionV1))
templateFile("pkg/apicontracts/apiresourcecontracts/resource_models_methods_generated.go.tmpl", rordefs.Resourcedefs.GetResourcesByVersion(rordefs.ApiVersionV1))

// Resource models v2
templateFile("pkg/rorresources/fromstruct.go.tmpl", rordefs.Resourcedefs.GetResourcesByVersion(rordefs.ApiVersionV2))
templateFile("pkg/rorresources/resource.go.tmpl", rordefs.Resourcedefs.GetResourcesByVersion(rordefs.ApiVersionV2))
templateFile("pkg/rorresources/rorkubernetes/k8s_test.go.tmpl", rordefs.Resourcedefs.GetResourcesByVersion(rordefs.ApiVersionV2))
templateFile("pkg/rorresources/rorkubernetes/k8s.go.tmpl", rordefs.Resourcedefs.GetResourcesByVersion(rordefs.ApiVersionV2))
templateFile("pkg/rorresources/rortypes/resource_interfaces.go.tmpl", rordefs.Resourcedefs.GetResourcesByVersion(rordefs.ApiVersionV2))
templateFile("pkg/rorresources/rortypes/resource_models_methods.go.tmpl", rordefs.Resourcedefs.GetResourcesByVersion(rordefs.ApiVersionV2))

// Resource models - input filters
for _, res := range rordefs.Resourcedefs {
for _, res := range rordefs.Resourcedefs.GetResourcesByVersion(rordefs.ApiVersionV2) {
filepath := fmt.Sprintf("pkg/rorresources/rortypes/resource_input_filter_%s.go", res.GetKind())
filepath = strings.ToLower(filepath)
templateFileOnce(filepath, "/pkg/rorresources/rortypes/resource_models_input_filter.go.tmpl", res)
templateFileOnce(filepath, "pkg/rorresources/rortypes/resource_models_input_filter.go.tmpl", res)
}

}
Expand Down
4 changes: 4 additions & 0 deletions pkg/rorresources/fromstruct.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ func NewResourceFromStruct(res Resource) *Resource {
r.SetNetworkPolicy(res.NetworkPolicyResource)
r.SetCommonInterface(res.NetworkPolicyResource)

case "infrastructure.ror.internal/v1alpha1, Kind=Datacenter":
r.SetDatacenter(res.DatacenterResource)
r.SetCommonInterface(res.DatacenterResource)

default:
rlog.Info("Unknown resource kind", rlog.String("gvk", gvk.String()), rlog.String("kind", res.Kind), rlog.String("apiVersion", res.APIVersion))
return nil
Expand Down
10 changes: 10 additions & 0 deletions pkg/rorresources/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Resource struct {
VirtualMachineResource *rortypes.ResourceVirtualMachine `json:"virtualmachine,omitempty" bson:"virtualmachine,omitempty"`
EndpointsResource *rortypes.ResourceEndpoints `json:"endpoints,omitempty" bson:"endpoints,omitempty"`
NetworkPolicyResource *rortypes.ResourceNetworkPolicy `json:"networkpolicy,omitempty" bson:"networkpolicy,omitempty"`
DatacenterResource *rortypes.ResourceDatacenter `json:"datacenter,omitempty" bson:"datacenter,omitempty"`

common rortypes.CommonResourceInterface
}
Expand Down Expand Up @@ -215,6 +216,10 @@ func (r *Resource) SetNetworkPolicy(res *rortypes.ResourceNetworkPolicy) {
r.NetworkPolicyResource = res
}

func (r *Resource) SetDatacenter(res *rortypes.ResourceDatacenter) {
r.DatacenterResource = res
}

// Namespace is a wrapper for the underlying resource, it provides a Namespaceinterface to work with namespaces
func (r *Resource) Namespace() rortypes.Namespaceinterface {
return r.NamespaceResource
Expand Down Expand Up @@ -395,6 +400,11 @@ func (r *Resource) NetworkPolicy() rortypes.NetworkPolicyinterface {
return r.NetworkPolicyResource
}

// Datacenter is a wrapper for the underlying resource, it provides a Datacenterinterface to work with datacenters
func (r *Resource) Datacenter() rortypes.Datacenterinterface {
return r.DatacenterResource
}

// (r *Resource) GetRorHash() returns the hash from the common interface
func (r *Resource) GetRorHash() string {
return r.common.GetRorHash()
Expand Down
Loading
Loading