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

2023-11-22 stable API (porting 07-01-preview api) #3300

Merged
merged 4 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -5,3 +5,4 @@ b1f1de0fe40d05de90742b17928968923b936adc294000f58974f50a297581dd swagger/redhat
01ba9562a8dac2824998ff0ad0d2465f79e6a66597bdb321e9409b9f2d12d222 swagger/redhatopenshift/resource-manager/Microsoft.RedHatOpenShift/stable/2023-04-01/redhatopenshift.json
c023515341196746454c0ae7af077d40d3ec13f6b88b33cb558f0a7ab17a5a24 swagger/redhatopenshift/resource-manager/Microsoft.RedHatOpenShift/preview/2023-07-01-preview/redhatopenshift.json
440748951dd1c3b34b5ccbdcb7cd966e3b89490887a1f1d64429561fad789515 swagger/redhatopenshift/resource-manager/Microsoft.RedHatOpenShift/stable/2023-09-04/redhatopenshift.json
98b241e3225ff4bbe96f4046aea98dae06c2bac2cc0e25ab8d85583bfc7f1861 swagger/redhatopenshift/resource-manager/Microsoft.RedHatOpenShift/stable/2023-11-22/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 2023-09-04
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 2023-11-22

# 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 @@ -25,6 +25,7 @@ import (
_ "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/api/v20231122"
"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/v20231122/clustermanager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
package v20231122

// 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/v20231122/clustermanager_validatestatic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package v20231122

// 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/v20231122/clustermanager_validatestatic_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package v20231122

// 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/v20231122/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package v20231122

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

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

// 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/v20231122/machinepool_example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package v20231122

// 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
Loading