-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: validate that started APIs have plans
- Loading branch information
Showing
12 changed files
with
154 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (C) 2015 The Gravitee team (http://gravitee.io) | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package base | ||
|
||
import ( | ||
"github.com/gravitee-io/gravitee-kubernetes-operator/internal/core" | ||
"github.com/gravitee-io/gravitee-kubernetes-operator/internal/errors" | ||
) | ||
|
||
func validatePlans(api core.ApiDefinitionObject) *errors.AdmissionError { | ||
if !api.HasPlans() && api.GetState() != "STOPPED" { | ||
return errors.NewSeveref( | ||
"cannot apply API [%s]. "+ | ||
"Its state is set to STARTED, but the API has no plans. "+ | ||
"APIs must have at least one plan in order to be deployed.", | ||
api.GetName(), | ||
) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
test/integration/admission/api/v2/create_withoutContext_andNoPlansWhileStarted_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (C) 2015 The Gravitee team (http://gravitee.io) | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package v2 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/gravitee-io/gravitee-kubernetes-operator/api/model/api/base" | ||
adm "github.com/gravitee-io/gravitee-kubernetes-operator/internal/admission/api/v2" | ||
"github.com/gravitee-io/gravitee-kubernetes-operator/internal/errors" | ||
"github.com/gravitee-io/gravitee-kubernetes-operator/test/internal/integration/constants" | ||
"github.com/gravitee-io/gravitee-kubernetes-operator/test/internal/integration/fixture" | ||
"github.com/gravitee-io/gravitee-kubernetes-operator/test/internal/integration/labels" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Validate create", labels.WithoutContext, func() { | ||
ctx := context.Background() | ||
admissionCtrl := adm.AdmissionCtrl{} | ||
|
||
It("should return error on API creation with no plans and state 'STARTED'", func() { | ||
fixtures := fixture. | ||
Builder(). | ||
WithAPI(constants.Api). | ||
Build() | ||
|
||
By("removing plans while API is started") | ||
|
||
fixtures.API.Spec.Plans = nil | ||
fixtures.API.Spec.State = base.StateStarted | ||
|
||
By("checking that API creation does not pass validation") | ||
|
||
_, err := admissionCtrl.ValidateCreate(ctx, fixtures.API) | ||
|
||
Expect(err).To(Equal( | ||
errors.NewSeveref( | ||
"cannot apply API [%s]. "+ | ||
"Its state is set to STARTED, but the API has no plans. "+ | ||
"APIs must have at least one plan in order to be deployed.", | ||
fixtures.API.GetName(), | ||
), | ||
)) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters