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

Add validation for Labels on Fleet and GS Template #1257

Merged
merged 1 commit into from
Jan 8, 2020

Conversation

aLekSer
Copy link
Collaborator

@aLekSer aLekSer commented Jan 3, 2020

Now ObjectMeta Labels part in a Fleet Template and GameServerSpec Template are
validated, as well as for GameServerSet Template field.

Closes #1244 .

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 3a3c2e98-e767-4776-b082-e2f9b8a715e7

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1257/head:pr_1257 && git checkout pr_1257
  • helm install ./install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.3.0-951ee33

@roberthbailey
Copy link
Member

@aLekSer - is this ready for review or are you still working on it?

@aLekSer aLekSer marked this pull request as ready for review January 6, 2020 20:24
@aLekSer
Copy link
Collaborator Author

aLekSer commented Jan 6, 2020

Code is ready for review.
Some tests could be added for GameServerSet, but it should work as for Fleet.
I will add Annotation validation in a separate PR because it is a different way of validating Annotations.

@markmandel markmandel added area/user-experience Pertaining to developers trying to use Agones, e.g. SDK, installation, etc kind/feature New features for Agones labels Jan 7, 2020
Copy link
Member

@roberthbailey roberthbailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why you added the validation.go and validation_test.go files in the vendor_fixes directory. I diff'd them against what was vendored in and they seemed identical.

func validateGSSpec(gs gsSpec) []metav1.StatusCause {
gsSpec := gs.GetGameServerSpec()
gsSpec.ApplyDefaults()
causes, _ := gsSpec.Validate("")

return causes
}

// validateObjectMeta Check ObjectMeta specification
// Used by Fleet, GameServerSet and Gameserver
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: GameServer (match case with elsewhere)

@@ -389,8 +389,12 @@ func (gss GameServerSpec) Validate(devAddress string) ([]metav1.StatusCause, boo
})
}
}
return causes, len(causes) == 0
objMetaCauses := validateObjectMeta(gss.Template.ObjectMeta)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the changes to this file (and gameserverset.go) have unit tests akin to what you added in fleet_test.go?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added similar test for gameserver .

for i := 0; i < nameLen; i++ {
key[i] = 'f'
}
flt.Spec.Template.ObjectMeta.Labels["label"] = string(key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be able to just do

flt.Spec.Template.ObjectMeta.Labels["label"] = strings.Repeat("f", validation.LabelValueMaxLength + 1)

See https://golang.org/pkg/strings/#Repeat

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, applying this to all connected code parts

for i := 0; i < nameLen; i++ {
key[i] = 'f'
}
f.Spec.Template.ObjectMeta.Labels["label"] = string(key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be able to just do f.Spec.Template.ObjectMeta.Labels["label"] = strings.Repeat("f", validation.LabelValueMaxLength + 1)

See https://golang.org/pkg/strings/#Repeat

assert.Equal(t, metav1.CauseTypeFieldValueInvalid, statusErr.Status().Details.Causes[0].Type)
goodFlt := defaultFleet(defaultNs)
goodFlt.Spec.Template.ObjectMeta.Labels = make(map[string]string)
goodFlt.Spec.Template.ObjectMeta.Labels["label"] = string(key[0 : nameLen-1])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goodFlt.Spec.Template.ObjectMeta.Labels["label"] = strings.Repeat("f", validation.LabelValueMaxLength)

@aLekSer
Copy link
Collaborator Author

aLekSer commented Jan 8, 2020

It seems that I did not configure local go properly. make test-go works fine.
A reason for adding api-machinery to both ./vendor and ./vendor_fixes was this issue, we have go.mod which

replace k8s.io/apimachinery => ./vendor_fixes/k8s.io/apimachinery
> go test
common.go:21:2: module k8s.io/apimachinery@latest (v0.17.0) found, but does not contain package k8s.io/apimachinery/pkg/apis/meta/v1/validation

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 4eb39e22-af92-4c05-b623-3c37f4d887d3

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1257/head:pr_1257 && git checkout pr_1257
  • helm install ./install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.3.0-882aee5

Now ObjectMeta in a Fleet Template and GameServerSpec Template are
validated, as well as for GameServerSet Template field.
@aLekSer
Copy link
Collaborator Author

aLekSer commented Jan 8, 2020

Removed unnecessary duplicate files out of ./vendor_fixes. Added more UTs for GSS, Fleet and GS.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: d56975cd-5161-46b5-b221-706fe894f766

The following development artifacts have been built, and will exist for the next 30 days:

A preview of the website (the last 30 builds are retained):

To install this version:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1257/head:pr_1257 && git checkout pr_1257
  • helm install ./install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.3.0-3443da6

@google-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aLekSer, roberthbailey

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@roberthbailey roberthbailey merged commit e3ae311 into googleforgames:master Jan 8, 2020
@markmandel markmandel added this to the 1.3.0 milestone Jan 10, 2020
@aLekSer aLekSer deleted the fix/fleet-label branch January 13, 2020 15:49
ilkercelikyilmaz pushed a commit to ilkercelikyilmaz/agones that referenced this pull request Oct 23, 2020
Now ObjectMeta in a Fleet Template and GameServerSpec Template are
validated, as well as for GameServerSet Template field.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved area/user-experience Pertaining to developers trying to use Agones, e.g. SDK, installation, etc kind/feature New features for Agones lgtm size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fleet/GameServerSet Validation: Able to create a Fleet with label and annotations length > 63 symbols
5 participants