Skip to content

Commit

Permalink
implement v2rortypes and datacenter
Browse files Browse the repository at this point in the history
  • Loading branch information
havardelnan committed Jan 14, 2025
1 parent 2f9963f commit b149771
Show file tree
Hide file tree
Showing 11 changed files with 314 additions and 103 deletions.
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

0 comments on commit b149771

Please sign in to comment.