This commit is contained in:
Jim Minter 2020-02-24 08:52:11 -06:00
Родитель 2fb6044abf
Коммит d60236fffb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 0730CBDA10D1A2D3
9 изменённых файлов: 94 добавлений и 15 удалений

Просмотреть файл

@ -9,11 +9,13 @@ import (
"encoding/base64"
"fmt"
"os"
"strings"
"github.com/containers/image/types"
"github.com/sirupsen/logrus"
pkgmirror "github.com/Azure/ARO-RP/pkg/mirror"
"github.com/Azure/ARO-RP/pkg/util/version"
)
func getAuth(key string) (*types.DockerAuthConfig, error) {
@ -60,6 +62,23 @@ func mirror(ctx context.Context, log *logrus.Entry) error {
return err
}
// ensure we mirror the version at which we are creating clusters, even if
// it isn't in the Cincinnati graph yet
var found bool
for _, release := range releases {
if release.Version == version.OpenShiftVersion {
found = true
break
}
}
if !found {
releases = append(releases, pkgmirror.Node{
Version: version.OpenShiftVersion,
Payload: strings.Replace(version.OpenShiftPullSpec, "arosvc.azurecr.io/", "quay.io/", 1),
})
}
var errorOccurred bool
for _, release := range releases {
log.Printf("mirroring release %s", release.Version)

Просмотреть файл

@ -16,6 +16,7 @@ import (
"github.com/Azure/ARO-RP/pkg/api/validate"
"github.com/Azure/ARO-RP/pkg/util/immutable"
"github.com/Azure/ARO-RP/pkg/util/subnet"
"github.com/Azure/ARO-RP/pkg/util/version"
)
type openShiftClusterStaticValidator struct {
@ -40,7 +41,7 @@ func (sv *openShiftClusterStaticValidator) Static(_oc interface{}, _current *api
return err
}
err = sv.validate(oc)
err = sv.validate(oc, current == nil)
if err != nil {
return err
}
@ -52,7 +53,7 @@ func (sv *openShiftClusterStaticValidator) Static(_oc interface{}, _current *api
return sv.validateDelta(oc, current)
}
func (sv *openShiftClusterStaticValidator) validate(oc *OpenShiftCluster) error {
func (sv *openShiftClusterStaticValidator) validate(oc *OpenShiftCluster, isCreate bool) error {
if !strings.EqualFold(oc.ID, sv.resourceID) {
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeMismatchingResourceID, "id", "The provided resource ID '%s' did not match the name in the Url '%s'.", oc.ID, sv.resourceID)
}
@ -66,10 +67,10 @@ func (sv *openShiftClusterStaticValidator) validate(oc *OpenShiftCluster) error
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, "location", "The provided location '%s' is invalid.", oc.Location)
}
return sv.validateProperties("properties", &oc.Properties)
return sv.validateProperties("properties", &oc.Properties, isCreate)
}
func (sv *openShiftClusterStaticValidator) validateProperties(path string, p *Properties) error {
func (sv *openShiftClusterStaticValidator) validateProperties(path string, p *Properties, isCreate bool) error {
switch p.ProvisioningState {
case ProvisioningStateCreating, ProvisioningStateUpdating,
ProvisioningStateDeleting, ProvisioningStateSucceeded,
@ -77,7 +78,7 @@ func (sv *openShiftClusterStaticValidator) validateProperties(path string, p *Pr
default:
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, path+".provisioningState", "The provided provisioning state '%s' is invalid.", p.ProvisioningState)
}
if err := sv.validateClusterProfile(path+".clusterProfile", &p.ClusterProfile); err != nil {
if err := sv.validateClusterProfile(path+".clusterProfile", &p.ClusterProfile, isCreate); err != nil {
return err
}
if err := sv.validateConsoleProfile(path+".consoleProfile", &p.ConsoleProfile); err != nil {
@ -111,13 +112,12 @@ func (sv *openShiftClusterStaticValidator) validateProperties(path string, p *Pr
return nil
}
func (sv *openShiftClusterStaticValidator) validateClusterProfile(path string, cp *ClusterProfile) error {
func (sv *openShiftClusterStaticValidator) validateClusterProfile(path string, cp *ClusterProfile, isCreate bool) error {
if !validate.RxDomainName.MatchString(cp.Domain) {
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, path+".domain", "The provided domain '%s' is invalid.", cp.Domain)
}
switch cp.Version {
case "", "4.3.0":
default:
if isCreate && cp.Version != version.OpenShiftVersion ||
!isCreate && !validate.RxOpenShiftVersion.MatchString(cp.Version) {
return api.NewCloudError(http.StatusBadRequest, api.CloudErrorCodeInvalidParameter, path+".version", "The provided version '%s' is invalid.", cp.Version)
}
if !validate.RxResourceGroupID.MatchString(cp.ResourceGroupID) {

Просмотреть файл

@ -545,7 +545,7 @@ func TestOpenShiftClusterStaticValidateDelta(t *testing.T) {
},
{
name: "version change",
modify: func(oc *OpenShiftCluster) { oc.Properties.ClusterProfile.Version = "" },
modify: func(oc *OpenShiftCluster) { oc.Properties.ClusterProfile.Version = "4.3.999" },
wantErr: "400: PropertyChangeNotAllowed: properties.clusterProfile.version: Changing property 'properties.clusterProfile.version' is not allowed.",
},
{

Просмотреть файл

@ -15,4 +15,5 @@ var (
`([a-z0-9]|[a-z0-9][-a-z0-9]{0,61}[a-z0-9])` +
`(\.([a-z0-9]|[a-z0-9][-a-z0-9]{0,61}[a-z0-9]))*` +
`$`)
RxOpenShiftVersion = regexp.MustCompile(`^4\.3\.(?:0|[1-9][0-9]{0,2})$`)
)

Просмотреть файл

@ -0,0 +1,41 @@
package validate
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"testing"
)
func TestRxOpenShiftVersion(t *testing.T) {
for _, tt := range []struct {
value string
want bool
}{
{
value: "4.3.0",
want: true,
},
{
value: "4.3.1",
want: true,
},
{
value: "4.3.999",
want: true,
},
{
value: "4.3.1000",
},
{
value: "4.3.01",
},
} {
t.Run(tt.value, func(t *testing.T) {
got := RxOpenShiftVersion.MatchString(tt.value)
if got != tt.want {
t.Error(got)
}
})
}
}

Просмотреть файл

@ -33,6 +33,7 @@ import (
"github.com/Azure/ARO-RP/pkg/install"
"github.com/Azure/ARO-RP/pkg/util/stringutils"
"github.com/Azure/ARO-RP/pkg/util/subnet"
"github.com/Azure/ARO-RP/pkg/util/version"
)
func (m *Manager) Create(ctx context.Context) error {
@ -219,10 +220,9 @@ func (m *Manager) Create(ctx context.Context) error {
}
image := &releaseimage.Image{}
switch m.doc.OpenShiftCluster.Properties.ClusterProfile.Version {
case "4.3.0":
image.PullSpec = "arosvc.azurecr.io/openshift-release-dev/ocp-release@sha256:3a516480dfd68e0f87f702b4d7bdd6f6a0acfdac5cd2e9767b838ceede34d70d"
default:
if m.doc.OpenShiftCluster.Properties.ClusterProfile.Version == version.OpenShiftVersion {
image.PullSpec = version.OpenShiftPullSpec
} else {
return fmt.Errorf("unimplemented version %q", m.doc.OpenShiftCluster.Properties.ClusterProfile.Version)
}

Просмотреть файл

@ -20,6 +20,7 @@ import (
"github.com/Azure/ARO-RP/pkg/api/admin"
"github.com/Azure/ARO-RP/pkg/database/cosmosdb"
"github.com/Azure/ARO-RP/pkg/frontend/middleware"
"github.com/Azure/ARO-RP/pkg/util/version"
)
func (f *frontend) putOrPatchOpenShiftCluster(w http.ResponseWriter, r *http.Request) {
@ -69,6 +70,9 @@ func (f *frontend) _putOrPatchOpenShiftCluster(ctx context.Context, r *http.Requ
Type: originalR.Provider + "/" + originalR.ResourceType,
Properties: api.Properties{
ProvisioningState: api.ProvisioningStateSucceeded,
ClusterProfile: api.ClusterProfile{
Version: version.OpenShiftVersion,
},
ServicePrincipalProfile: api.ServicePrincipalProfile{
TenantID: subdoc.Subscription.Properties.TenantID,
},
@ -104,6 +108,9 @@ func (f *frontend) _putOrPatchOpenShiftCluster(ctx context.Context, r *http.Requ
Type: doc.OpenShiftCluster.Type,
Properties: api.Properties{
ProvisioningState: doc.OpenShiftCluster.Properties.ProvisioningState,
ClusterProfile: api.ClusterProfile{
Version: doc.OpenShiftCluster.Properties.ClusterProfile.Version,
},
},
})
@ -133,7 +140,6 @@ func (f *frontend) _putOrPatchOpenShiftCluster(ctx context.Context, r *http.Requ
doc.ClusterResourceGroupIDKey = strings.ToLower(doc.OpenShiftCluster.Properties.ClusterProfile.ResourceGroupID)
doc.ClientIDKey = strings.ToLower(doc.OpenShiftCluster.Properties.ServicePrincipalProfile.ClientID)
doc.OpenShiftCluster.Properties.ProvisioningState = api.ProvisioningStateCreating
doc.OpenShiftCluster.Properties.ClusterProfile.Version = "4.3.0"
doc.Bucket, err = f.bucketAllocator.Allocate()
if err != nil {

Просмотреть файл

@ -114,6 +114,9 @@ func TestPutOrPatchOpenShiftCluster(t *testing.T) {
{
name: "create a new cluster",
resourceID: fmt.Sprintf("/subscriptions/%s/resourcegroups/resourceGroup/providers/Microsoft.RedHatOpenShift/openshiftClusters/resourceName", mockSubID),
request: func(oc *v20191231preview.OpenShiftCluster) {
oc.Properties.ClusterProfile.Version = "4.3.0"
},
mocks: func(tt *test, asyncOperations *mock_database.MockAsyncOperations, openShiftClusters *mock_database.MockOpenShiftClusters) {
openShiftClusters.EXPECT().
Get(gomock.Any(), strings.ToLower(tt.resourceID)).

Просмотреть файл

@ -0,0 +1,9 @@
package version
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
const (
OpenShiftVersion = "4.3.3"
OpenShiftPullSpec = "arosvc.azurecr.io/openshift-release-dev/ocp-release@sha256:9b8708b67dd9b7720cb7ab3ed6d12c394f689cc8927df0e727c76809ab383f44"
)