зеркало из https://github.com/Azure/ARO-RP.git
refactor openshiftversion api models
This commit is contained in:
Родитель
706bcb1258
Коммит
298d153192
|
@ -10,6 +10,19 @@ type OpenShiftVersionList struct {
|
|||
}
|
||||
|
||||
type OpenShiftVersion struct {
|
||||
// The ID for the resource.
|
||||
ID string `json:"id,omitempty"`
|
||||
|
||||
// Name of the resource.
|
||||
Name string `json:"name,omitempty"`
|
||||
|
||||
// The properties for the OpenShiftVersion resource.
|
||||
Properties OpenShiftVersionProperties `json:"properties,omitempty"`
|
||||
}
|
||||
|
||||
// OpenShiftVersionProperties represents the properties of an OpenShiftVersion.
|
||||
type OpenShiftVersionProperties struct {
|
||||
// Version represents the version to create the cluster at.
|
||||
Version string `json:"version,omitempty"`
|
||||
OpenShiftPullspec string `json:"openShiftPullspec,omitempty" mutable:"true"`
|
||||
InstallerPullspec string `json:"installerPullspec,omitempty" mutable:"true"`
|
||||
|
|
|
@ -16,10 +16,12 @@ type openShiftVersionConverter struct{}
|
|||
// returned objects.
|
||||
func (openShiftVersionConverter) ToExternal(v *api.OpenShiftVersion) interface{} {
|
||||
out := &OpenShiftVersion{
|
||||
Version: v.Version,
|
||||
OpenShiftPullspec: v.OpenShiftPullspec,
|
||||
InstallerPullspec: v.InstallerPullspec,
|
||||
Enabled: v.Enabled,
|
||||
Properties: OpenShiftVersionProperties{
|
||||
Version: v.Properties.Version,
|
||||
OpenShiftPullspec: v.Properties.OpenShiftPullspec,
|
||||
InstallerPullspec: v.Properties.InstallerPullspec,
|
||||
Enabled: v.Properties.Enabled,
|
||||
},
|
||||
}
|
||||
|
||||
return out
|
||||
|
@ -46,8 +48,8 @@ func (c openShiftVersionConverter) ToExternalList(vers []*api.OpenShiftVersion)
|
|||
func (c openShiftVersionConverter) ToInternal(_new interface{}, out *api.OpenShiftVersion) {
|
||||
new := _new.(*OpenShiftVersion)
|
||||
|
||||
out.Enabled = new.Enabled
|
||||
out.InstallerPullspec = new.InstallerPullspec
|
||||
out.OpenShiftPullspec = new.OpenShiftPullspec
|
||||
out.Version = new.Version
|
||||
out.Properties.Enabled = new.Properties.Enabled
|
||||
out.Properties.InstallerPullspec = new.Properties.InstallerPullspec
|
||||
out.Properties.OpenShiftPullspec = new.Properties.OpenShiftPullspec
|
||||
out.Properties.Version = new.Properties.Version
|
||||
}
|
||||
|
|
|
@ -34,15 +34,15 @@ func (sv openShiftVersionStaticValidator) Static(_new interface{}, _current *api
|
|||
}
|
||||
|
||||
func (sv openShiftVersionStaticValidator) validate(new *OpenShiftVersion, isCreate bool) error {
|
||||
if new.Version == "" {
|
||||
if new.Properties.Version == "" {
|
||||
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, "version", "Must be provided")
|
||||
}
|
||||
|
||||
if new.InstallerPullspec == "" {
|
||||
if new.Properties.InstallerPullspec == "" {
|
||||
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, "installerPullspec", "Must be provided")
|
||||
}
|
||||
|
||||
if new.OpenShiftPullspec == "" {
|
||||
if new.Properties.OpenShiftPullspec == "" {
|
||||
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, "openShiftPullspec", "Must be provided")
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
package installversion
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
||||
|
||||
// OpenShiftCluster represents the portion of the OpenShift cluster
|
||||
// representation which provides the cluster installation version.
|
||||
type openShiftCluster struct {
|
||||
Properties openShiftClusterProperties `json:"properties,omitempty"`
|
||||
}
|
||||
|
||||
// OpenShiftClusterProperties represents an OpenShift cluster's properties.
|
||||
type openShiftClusterProperties struct {
|
||||
// The cluster install version.
|
||||
InstallVersion string `json:"installVersion,omitempty"`
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package installversion
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
func FromExternalBytes(body []byte) (*openShiftCluster, error) {
|
||||
r := &openShiftCluster{}
|
||||
|
||||
err := json.Unmarshal(body, &r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return r, nil
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
package installversion
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
v20200430 "github.com/Azure/ARO-RP/pkg/api/v20200430"
|
||||
v20220904 "github.com/Azure/ARO-RP/pkg/api/v20220904"
|
||||
)
|
||||
|
||||
func TestParsePreInstallAPI(t *testing.T) {
|
||||
preInstallVersion := &v20200430.OpenShiftCluster{
|
||||
Properties: v20200430.OpenShiftClusterProperties{
|
||||
ClusterProfile: v20200430.ClusterProfile{
|
||||
Domain: "example",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
b, err := json.Marshal(preInstallVersion)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ver, err := FromExternalBytes(b)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if ver.Properties.InstallVersion != "" {
|
||||
t.Error(ver.Properties.InstallVersion)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsePostInstallAPI(t *testing.T) {
|
||||
postInstallVersion := &v20220904.OpenShiftCluster{
|
||||
Properties: v20220904.OpenShiftClusterProperties{
|
||||
ClusterProfile: v20220904.ClusterProfile{
|
||||
Domain: "example",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
b, err := json.Marshal(postInstallVersion)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ver, err := FromExternalBytes(b)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if ver.Properties.InstallVersion != "" {
|
||||
t.Error(ver.Properties.InstallVersion)
|
||||
}
|
||||
|
||||
postInstallVersionWithVersion := &v20220904.OpenShiftCluster{
|
||||
Properties: v20220904.OpenShiftClusterProperties{
|
||||
InstallVersion: "4.10.0",
|
||||
ClusterProfile: v20220904.ClusterProfile{
|
||||
Domain: "example",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
b, err = json.Marshal(postInstallVersionWithVersion)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ver, err = FromExternalBytes(b)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if ver.Properties.InstallVersion != "4.10.0" {
|
||||
t.Error(ver.Properties.InstallVersion)
|
||||
}
|
||||
}
|
|
@ -8,8 +8,17 @@ type OpenShiftVersion struct {
|
|||
MissingFields
|
||||
|
||||
ID string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Deleting bool `json:"deleting,omitempty"` // https://docs.microsoft.com/en-us/azure/cosmos-db/change-feed-design-patterns#deletes
|
||||
|
||||
// The properties for the OpenShiftVersion resource.
|
||||
Properties OpenShiftVersionProperties `json:"properties,omitempty"`
|
||||
}
|
||||
|
||||
// OpenShiftVersionProperties represents the properties of an OpenShiftVersion.
|
||||
type OpenShiftVersionProperties struct {
|
||||
// Version represents the version to create the cluster at.
|
||||
Version string `json:"version,omitempty"`
|
||||
OpenShiftPullspec string `json:"openShiftPullspec,omitempty"`
|
||||
InstallerPullspec string `json:"installerPullspec,omitempty"`
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package api
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
||||
|
||||
func ExampleOpenShiftVersionDocument() *OpenShiftVersionDocument {
|
||||
return &OpenShiftVersionDocument{
|
||||
MissingFields: MissingFields{},
|
||||
ID: "00000000-0000-0000-0000-000000000000",
|
||||
OpenShiftVersion: &OpenShiftVersion{
|
||||
ID: "00000000-0000-0000-0000-000000000000",
|
||||
Name: "default",
|
||||
Type: "Microsoft.RedHatOpenShift/OpenShiftVersion",
|
||||
Properties: OpenShiftVersionProperties{
|
||||
Version: "4.10.20",
|
||||
OpenShiftPullspec: "ab:c",
|
||||
InstallerPullspec: "de:f",
|
||||
Enabled: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
|
@ -35,10 +35,6 @@ type OpenShiftVersionConverter interface {
|
|||
ToInternal(interface{}, *OpenShiftVersion)
|
||||
}
|
||||
|
||||
type InstallVersionsConverter interface {
|
||||
ToExternal(*InstallVersions) interface{}
|
||||
}
|
||||
|
||||
type OpenShiftVersionStaticValidator interface {
|
||||
Static(interface{}, *OpenShiftVersion) error
|
||||
}
|
||||
|
@ -52,7 +48,6 @@ type Version struct {
|
|||
OpenShiftClusterAdminKubeconfigConverter OpenShiftClusterAdminKubeconfigConverter
|
||||
OpenShiftVersionConverter OpenShiftVersionConverter
|
||||
OpenShiftVersionStaticValidator OpenShiftVersionStaticValidator
|
||||
InstallVersionsConverter InstallVersionsConverter
|
||||
OperationList OperationList
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
package v20220904
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
||||
|
||||
// InstallVersions represents a List of OpenShift installable versions.
|
||||
type InstallVersions []InstallVersion
|
|
@ -1,12 +0,0 @@
|
|||
package v20220904
|
||||
|
||||
import "github.com/Azure/ARO-RP/pkg/api"
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
||||
|
||||
type installVersionsConverter struct{}
|
||||
|
||||
func (installVersionsConverter) ToExternal(installVersions *api.InstallVersions) interface{} {
|
||||
return installVersions
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package v20220904
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
||||
|
||||
// ExampleInstallVersions returns an example
|
||||
// InstallVersions object i.e []string that the RP would return to an end-user.
|
||||
func ExampleInstallVersionsResponse() interface{} {
|
||||
return &InstallVersions{"4.10.20"}
|
||||
}
|
|
@ -69,9 +69,6 @@ type OpenShiftClusterProperties struct {
|
|||
|
||||
// The cluster ingress profiles.
|
||||
IngressProfiles []IngressProfile `json:"ingressProfiles,omitempty"`
|
||||
|
||||
// The cluster install version.
|
||||
InstallVersion string `json:"installVersion,omitempty"`
|
||||
}
|
||||
|
||||
// ProvisioningState represents a provisioning state.
|
||||
|
@ -87,9 +84,6 @@ const (
|
|||
ProvisioningStateFailed ProvisioningState = "Failed"
|
||||
)
|
||||
|
||||
// InstallVersion is the OpenShift installation version string.
|
||||
type InstallVersion string
|
||||
|
||||
// FipsValidatedModules determines if FIPS is used.
|
||||
type FipsValidatedModules string
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@ func ExampleOpenShiftClusterPutParameter() interface{} {
|
|||
oc.Properties.APIServerProfile.IP = ""
|
||||
oc.Properties.IngressProfiles[0].IP = ""
|
||||
oc.Properties.MasterProfile.EncryptionAtHost = EncryptionAtHost(EncryptionAtHostEnabled)
|
||||
oc.Properties.InstallVersion = ""
|
||||
oc.SystemData = nil
|
||||
|
||||
return oc
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package v20220904
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
||||
|
||||
// OpenShiftVersionList represents a List of available versions.
|
||||
type OpenShiftVersionList struct {
|
||||
// The List of available versions.
|
||||
OpenShiftVersions []*OpenShiftVersion `json:"value"`
|
||||
|
||||
// Next Link to next operation.
|
||||
NextLink string `json:"nextLink,omitempty"`
|
||||
}
|
||||
|
||||
// OpenShiftVersion represents an OpenShift version that can be installed.
|
||||
type OpenShiftVersion struct {
|
||||
proxyResource bool
|
||||
|
||||
// The ID for the resource.
|
||||
ID string `json:"id,omitempty" mutable:"case"`
|
||||
|
||||
// Name of the resource.
|
||||
Name string `json:"name,omitempty" mutable:"case"`
|
||||
|
||||
// The resource type.
|
||||
Type string `json:"type,omitempty" mutable:"case"`
|
||||
|
||||
// The properties for the OpenShiftVersion resource.
|
||||
Properties OpenShiftVersionProperties `json:"properties,omitempty"`
|
||||
}
|
||||
|
||||
// OpenShiftVersionProperties represents the properties of an OpenShiftVersion.
|
||||
type OpenShiftVersionProperties struct {
|
||||
// Version represents the version to create the cluster at.
|
||||
Version string `json:"version,omitempty"`
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package v20220904
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
||||
|
||||
import (
|
||||
"github.com/Azure/ARO-RP/pkg/api"
|
||||
)
|
||||
|
||||
type openShiftVersionConverter struct{}
|
||||
|
||||
// openShiftVersionConverter.ToExternal returns a new external representation
|
||||
// of the internal object, reading from the subset of the internal object's
|
||||
// fields that appear in the external representation. ToExternal does not
|
||||
// modify its argument; there is no pointer aliasing between the passed and
|
||||
// returned objects.
|
||||
func (openShiftVersionConverter) ToExternal(v *api.OpenShiftVersion) interface{} {
|
||||
out := &OpenShiftVersion{
|
||||
proxyResource: true,
|
||||
Properties: OpenShiftVersionProperties{
|
||||
Version: v.Properties.Version,
|
||||
},
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
|
||||
// ToExternalList returns a slice of external representations of the internal
|
||||
// objects
|
||||
func (c openShiftVersionConverter) ToExternalList(vers []*api.OpenShiftVersion) interface{} {
|
||||
l := &OpenShiftVersionList{
|
||||
OpenShiftVersions: make([]*OpenShiftVersion, 0, len(vers)),
|
||||
}
|
||||
|
||||
for _, ver := range vers {
|
||||
l.OpenShiftVersions = append(l.OpenShiftVersions, c.ToExternal(ver).(*OpenShiftVersion))
|
||||
}
|
||||
|
||||
return l
|
||||
}
|
||||
|
||||
// ToInternal overwrites in place a pre-existing internal object, setting (only)
|
||||
// all mapped fields from the external representation. ToInternal modifies its
|
||||
// argument; there is no pointer aliasing between the passed and returned
|
||||
// objects
|
||||
func (c openShiftVersionConverter) ToInternal(_new interface{}, out *api.OpenShiftVersion) {
|
||||
new := _new.(*OpenShiftVersion)
|
||||
out.Properties.Version = new.Properties.Version
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package v20220904
|
||||
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the Apache License 2.0.
|
||||
|
||||
import "github.com/Azure/ARO-RP/pkg/api"
|
||||
|
||||
func exampleOpenShiftVersion() *OpenShiftVersion {
|
||||
doc := api.ExampleOpenShiftVersionDocument()
|
||||
ext := (&openShiftVersionConverter{}).ToExternal(doc.OpenShiftVersion)
|
||||
return ext.(*OpenShiftVersion)
|
||||
}
|
||||
|
||||
func ExampleOpenShiftVersionResponse() interface{} {
|
||||
return exampleOpenShiftVersion()
|
||||
}
|
||||
|
||||
func ExampleOpenShiftVersionListResponse() interface{} {
|
||||
return &OpenShiftVersionList{
|
||||
OpenShiftVersions: []*OpenShiftVersion{
|
||||
ExampleOpenShiftVersionResponse().(*OpenShiftVersion),
|
||||
},
|
||||
}
|
||||
}
|
|
@ -21,7 +21,7 @@ func init() {
|
|||
OpenShiftClusterStaticValidator: openShiftClusterStaticValidator{},
|
||||
OpenShiftClusterCredentialsConverter: openShiftClusterCredentialsConverter{},
|
||||
OpenShiftClusterAdminKubeconfigConverter: openShiftClusterAdminKubeconfigConverter{},
|
||||
InstallVersionsConverter: installVersionsConverter{},
|
||||
OpenShiftVersionConverter: openShiftVersionConverter{},
|
||||
OperationList: api.OperationList{
|
||||
Operations: []api.Operation{
|
||||
api.OperationResultsRead,
|
||||
|
|
Загрузка…
Ссылка в новой задаче