-
Notifications
You must be signed in to change notification settings - Fork 828
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing validation for GameServerSet, refactor
Add common file which contains all common validations for GS, GSSet and Fleet. Add const for some err messages. GSSet now checks Name on Update and GS Spec on Create.
- Loading branch information
Showing
7 changed files
with
136 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2019 Google LLC All Rights Reserved. | ||
// | ||
// 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 v1alpha1 | ||
|
||
import ( | ||
"fmt" | ||
|
||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apimachinery/pkg/util/validation" | ||
) | ||
|
||
// Block of const Error messages | ||
const ( | ||
ErrContainerRequired = "Container is required when using multiple containers in the pod template" | ||
ErrHostPortDynamic = "HostPort cannot be specified with a Dynamic PortPolicy" | ||
ErrPortPolicyStatic = "PortPolicy must be Static" | ||
) | ||
|
||
// crdName is an interface to get Name and Kind of CRD | ||
type crdName interface { | ||
GetName() string | ||
GetObjectKind() schema.ObjectKind | ||
} | ||
|
||
// validateName Check NameSize of a CRD | ||
func validateName(cs crdName) []v1.StatusCause { | ||
var causes []v1.StatusCause | ||
name := cs.GetName() | ||
kind := cs.GetObjectKind().GroupVersionKind().Kind | ||
// make sure the Name of a Fleet does not oversize the Label size in GSS and GS | ||
if len(name) > validation.LabelValueMaxLength { | ||
causes = append(causes, v1.StatusCause{ | ||
Type: v1.CauseTypeFieldValueInvalid, | ||
Field: fmt.Sprintf("Name"), | ||
Message: fmt.Sprintf("Length of %s '%s' name should be no more than 63 characters.", kind, name), | ||
}) | ||
} | ||
return causes | ||
} | ||
|
||
// gsSpec is an interface which contains all necessary | ||
// functions to perform common validations against it | ||
type gsSpec interface { | ||
GetGameServerSpec() *GameServerSpec | ||
} | ||
|
||
// validateGSSpec Check GameserverSpec of a CRD | ||
// Used by Fleet and Gameserverset | ||
func validateGSSpec(gs gsSpec) []v1.StatusCause { | ||
gsSpec := gs.GetGameServerSpec() | ||
gsSpec.ApplyDefaults() | ||
causes, _ := gsSpec.Validate("") | ||
|
||
return causes | ||
} |
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