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

skeleton for 20230904 #3048

Merged
merged 3 commits into from
Jul 21, 2023
Merged
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
1 change: 1 addition & 0 deletions .sha256sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
1d167031baf0209fe8c46df9654585c64e8cc9a0c89555d7479c4ed6dc150251 swagger/redhatopenshift/resource-manager/Microsoft.RedHatOpenShift/stable/2022-09-04/redhatopenshift.json
622404e8311c62f27fba778e30e760bb1901e5bd221b23de72f449cafbdf0c45 swagger/redhatopenshift/resource-manager/Microsoft.RedHatOpenShift/stable/2023-04-01/redhatopenshift.json
4df3ebacaf35d77d09f5eab75fb9608241929b6ef8d00fb506455cd38e383640 swagger/redhatopenshift/resource-manager/Microsoft.RedHatOpenShift/preview/2023-07-01-preview/redhatopenshift.json
gouthamMN marked this conversation as resolved.
Show resolved Hide resolved
415605101b133e4277711cdac0dd5f95112fbffca2376c7728f35b6c9700f794 swagger/redhatopenshift/resource-manager/Microsoft.RedHatOpenShift/stable/2023-09-04/redhatopenshift.json
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ clean:
find -type d -name 'gomock_reflect_[0-9]*' -exec rm -rf {} \+ 2>/dev/null

client: generate
hack/build-client.sh "${AUTOREST_IMAGE}" 2020-04-30 2021-09-01-preview 2022-04-01 2022-09-04 2023-04-01 2023-07-01-preview
hack/build-client.sh "${AUTOREST_IMAGE}" 2020-04-30 2021-09-01-preview 2022-04-01 2022-09-04 2023-04-01 2023-07-01-preview 2023-09-04

# TODO: hard coding dev-config.yaml is clunky; it is also probably convenient to
# override COMMIT.
Expand Down
1 change: 1 addition & 0 deletions cmd/aro/rp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
_ "github.com/Azure/ARO-RP/pkg/api/v20220904"
_ "github.com/Azure/ARO-RP/pkg/api/v20230401"
_ "github.com/Azure/ARO-RP/pkg/api/v20230701preview"
_ "github.com/Azure/ARO-RP/pkg/api/v20230904"
"github.com/Azure/ARO-RP/pkg/backend"
"github.com/Azure/ARO-RP/pkg/database"
"github.com/Azure/ARO-RP/pkg/env"
Expand Down
154 changes: 154 additions & 0 deletions pkg/api/v20230904/clustermanager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package v20230904

// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.

// SyncSetList represents a list of SyncSets
type SyncSetList struct {
// The list of syncsets.
SyncSets []*SyncSet `json:"value"`

// The link used to get the next page of operations.
NextLink string `json:"nextLink,omitempty"`
}

// SyncSet represents a SyncSet for an Azure Red Hat OpenShift Cluster.
type SyncSet struct {
// This is a flag used during the swagger generation typewalker to
// signal that it should be marked as a proxy resource and
// not a tracked ARM resource.
proxyResource bool

// The resource ID.
ID string `json:"id,omitempty" mutable:"case"`

// The resource name.
Name string `json:"name,omitempty" mutable:"case"`

// The resource type.
Type string `json:"type,omitempty" mutable:"case"`

// SystemData metadata relating to this resource.
SystemData *SystemData `json:"systemData,omitempty"`

// The Syncsets properties
Properties SyncSetProperties `json:"properties,omitempty"`
}

// SyncSetProperties represents the properties of a SyncSet
type SyncSetProperties struct {
// Resources represents the SyncSets configuration.
Resources string `json:"resources,omitempty"`
}

// MachinePoolList represents a list of MachinePools
type MachinePoolList struct {
// The list of Machine Pools.
MachinePools []*MachinePool `json:"value"`

// The link used to get the next page of operations.
NextLink string `json:"nextLink,omitempty"`
}

// MachinePool represents a MachinePool
type MachinePool struct {
// This is a flag used during the swagger generation typewalker to
// signal that it should be marked as a proxy resource and
// not a tracked ARM resource.
proxyResource bool

// The Resource ID.
ID string `json:"id,omitempty"`

// The resource name.
Name string `json:"name,omitempty"`

// The resource type.
Type string `json:"type,omitempty" mutable:"case"`

// SystemData metadata relating to this resource.
SystemData *SystemData `json:"systemData,omitempty"`

// The MachinePool Properties
Properties MachinePoolProperties `json:"properties,omitempty"`
}

// MachinePoolProperties represents the properties of a MachinePool
type MachinePoolProperties struct {
Resources string `json:"resources,omitempty"`
}

// SyncSetList represents a list of SyncSets
type SyncIdentityProviderList struct {
// The list of sync identity providers
SyncIdentityProviders []*SyncIdentityProvider `json:"value"`

// The link used to get the next page of operations.
NextLink string `json:"nextLink,omitempty"`
}

// SyncIdentityProvider represents a SyncIdentityProvider
type SyncIdentityProvider struct {
// This is a flag used during the swagger generation typewalker to
// signal that it should be marked as a proxy resource and
// not a tracked ARM resource.
proxyResource bool

// The Resource ID.
ID string `json:"id,omitempty"`

// The resource name.
Name string `json:"name,omitempty"`

// The resource type.
Type string `json:"type,omitempty" mutable:"case"`

// SystemData metadata relating to this resource.
SystemData *SystemData `json:"systemData,omitempty"`

// The SyncIdentityProvider Properties
Properties SyncIdentityProviderProperties `json:"properties,omitempty"`
}

// SyncSetProperties represents the properties of a SyncSet
type SyncIdentityProviderProperties struct {
Resources string `json:"resources,omitempty"`
}

// SecretList represents a list of Secrets
type SecretList struct {
// The list of secrets.
Secrets []*Secret `json:"value"`

// The link used to get the next page of operations.
NextLink string `json:"nextLink,omitempty"`
}

// Secret represents a secret.
type Secret struct {
// This is a flag used during the swagger generation typewalker to
// signal that it should be marked as a proxy resource and
// not a tracked ARM resource.
proxyResource bool

// The Resource ID.
ID string `json:"id,omitempty"`

// The resource name.
Name string `json:"name,omitempty"`

// The resource type.
Type string `json:"type,omitempty" mutable:"case"`

// SystemData metadata relating to this resource.
SystemData *SystemData `json:"systemData,omitempty"`

// The Secret Properties
Properties SecretProperties `json:"properties,omitempty"`
}

// SecretProperties represents the properties of a Secret
type SecretProperties struct {
// The Secrets Resources.
SecretResources string `json:"secretResources,omitempty"`
}
37 changes: 37 additions & 0 deletions pkg/api/v20230904/clustermanager_validatestatic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package v20230904

// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.

import (
"encoding/base64"
"encoding/json"
"fmt"
"strings"
)

type clusterManagerStaticValidator struct{}

func (c clusterManagerStaticValidator) Static(body string, ocmResourceType string) error {
var resource map[string]interface{}

if decodedBody, err := base64.StdEncoding.DecodeString(body); err == nil {
err = json.Unmarshal(decodedBody, &resource)
if err != nil {
return err
}
} else {
b := []byte(body)
err := json.Unmarshal(b, &resource)
if err != nil {
return err
}
}

payloadResourceKind := strings.ToLower(resource["kind"].(string))
if payloadResourceKind != ocmResourceType {
return fmt.Errorf("wanted Kind '%v', resource is Kind '%v'", ocmResourceType, payloadResourceKind)
}

return nil
}
82 changes: 82 additions & 0 deletions pkg/api/v20230904/clustermanager_validatestatic_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package v20230904

// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.

import (
"fmt"
"testing"
)

var ocmResource = string(`
{
"apiVersion": "hive.openshift.io/v1",
"kind": "SyncSet",
"metadata": {
"name": "sample",
"namespace": "aro-f60ae8a2-bca1-4987-9056-f2f6a1837caa"
},
"spec": {
"clusterDeploymentRefs": [],
"resources": [
{
"apiVersion": "v1",
"kind": "ConfigMap",
"metadata": {
"name": "myconfigmap"
}
}
]
}
}
`)

var ocmResourceEncoded = "eyAKICAiYXBpVmVyc2lvbiI6ICJoaXZlLm9wZW5zaGlmdC5pby92MSIsCiAgImtpbmQiOiAiU3luY1NldCIsCiAgIm1ldGFkYXRhIjogewogICAgIm5hbWUiOiAic2FtcGxlIiwKICAgICJuYW1lc3BhY2UiOiAiYXJvLWY2MGFlOGEyLWJjYTEtNDk4Ny05MDU2LWYyZjZhMTgzN2NhYSIKICB9LAogICJzcGVjIjogewogICAgImNsdXN0ZXJEZXBsb3ltZW50UmVmcyI6IFtdLAogICAgInJlc291cmNlcyI6IFsKICAgICAgewogICAgICAgICJhcGlWZXJzaW9uIjogInYxIiwKICAgICAgICAia2luZCI6ICJDb25maWdNYXAiLAogICAgICAgICJtZXRhZGF0YSI6IHsKICAgICAgICAgICJuYW1lIjogIm15Y29uZmlnbWFwIgogICAgICAgIH0KICAgICAgfQogICAgXQogIH0KfQo="

func TestStatic(t *testing.T) {
for _, tt := range []struct {
name string
ocmResource string
ocmResourceType string
wantErr bool
err string
}{
{
name: "payload Kind matches",
ocmResource: ocmResource,
ocmResourceType: "syncset",
wantErr: false,
},
{
name: "payload Kind matches and is a base64 encoded string",
ocmResource: ocmResourceEncoded,
ocmResourceType: "syncset",
wantErr: false,
},
{
name: "payload Kind does not match",
ocmResource: ocmResource,
ocmResourceType: "route",
wantErr: true,
err: "wanted Kind 'route', resource is Kind 'syncset'",
},
{
name: "payload Kind does not match and is a base64 encoded string",
ocmResource: ocmResourceEncoded,
ocmResourceType: "route",
wantErr: true,
err: "wanted Kind 'route', resource is Kind 'syncset'",
},
} {
t.Run(tt.name, func(t *testing.T) {
c := &clusterManagerStaticValidator{}

err := c.Static(tt.ocmResource, tt.ocmResourceType)
if err != nil && tt.wantErr {
if fmt.Sprint(err) != tt.err {
t.Errorf("wanted '%v', got '%v'", tt.err, err)
}
}
})
}
}
6 changes: 6 additions & 0 deletions pkg/api/v20230904/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package v20230904

// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.

//go:generate go run ../../../hack/swagger github.com/Azure/ARO-RP/pkg/api/v20230904 ../../../swagger/redhatopenshift/resource-manager/Microsoft.RedHatOpenShift/stable/2023-09-04
39 changes: 39 additions & 0 deletions pkg/api/v20230904/machinepool_convert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package v20230904

// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.

import (
"github.com/Azure/ARO-RP/pkg/api"
)

type machinePoolConverter struct{}

func (c machinePoolConverter) ToExternal(mp *api.MachinePool) interface{} {
out := new(MachinePool)
out.proxyResource = true
out.ID = mp.ID
out.Name = mp.Name
out.Type = mp.Type
out.Properties.Resources = mp.Properties.Resources
return out
}

func (c machinePoolConverter) ToInternal(_mp interface{}, out *api.MachinePool) {
ocm := _mp.(*api.MachinePool)
out.ID = ocm.ID
}

// ToExternalList returns a slice of external representations of the internal objects
func (c machinePoolConverter) ToExternalList(mp []*api.MachinePool) interface{} {
l := &MachinePoolList{
MachinePools: make([]*MachinePool, 0, len(mp)),
}

for _, machinepool := range mp {
c := c.ToExternal(machinepool)
l.MachinePools = append(l.MachinePools, c.(*MachinePool))
}

return l
}
38 changes: 38 additions & 0 deletions pkg/api/v20230904/machinepool_example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package v20230904

// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.

import (
"github.com/Azure/ARO-RP/pkg/api"
)

func exampleMachinePool() *MachinePool {
doc := api.ExampleClusterManagerConfigurationDocumentMachinePool()
ext := (&machinePoolConverter{}).ToExternal(doc.MachinePool)
return ext.(*MachinePool)
}

func ExampleMachinePoolPutParameter() interface{} {
mp := exampleMachinePool()
mp.ID = ""
mp.Type = ""
mp.Name = ""
return mp
}

func ExampleMachinePoolPatchParameter() interface{} {
return ExampleMachinePoolPutParameter()
}

func ExampleMachinePoolResponse() interface{} {
return exampleMachinePool()
}

func ExampleMachinePoolListResponse() interface{} {
return &MachinePoolList{
MachinePools: []*MachinePool{
ExampleMachinePoolResponse().(*MachinePool),
},
}
}
Loading