-
Notifications
You must be signed in to change notification settings - Fork 843
App and pod validation errors for missing network name MARATHON-7398 #5432
App and pod validation errors for missing network name MARATHON-7398 #5432
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Alena,
great PR! Thank you for taking the time to complete fix this issue. Just a really minor comment from my side, but no hurdle to merge.
Thanks
Johannes
val configWithDefaultNetworkName = AppNormalization.Configuration(Some("defaultNetworkName"), "mesos-bridge-name") | ||
implicit val basicValidator: Validator[App] = AppValidation.validateCanonicalAppAPI(Set.empty, config) | ||
implicit val withSecretsValidator: Validator[App] = AppValidation.validateCanonicalAppAPI(Set("secrets"), config) | ||
implicit val withDefaultNetworkNameValidator: Validator[App] = AppValidation.validateCanonicalAppAPI(Set.empty, configWithDefaultNetworkName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont know why basicValidator
and withSecretsValidator
are declared as implicit, but I think we should change all three validators to regular vars.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, redundant implicit types are strange here. it's not the OPs job to fix, but I'd like to suggest that we at least refrain from continuing the pattern: withDefaultNetworkNameValidator
should not be implicit.
Hey @jdef, when your back after US holidays, could you have a look, this would be awesome! Thanks =) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the PR, left some feedback
@@ -304,7 +305,7 @@ trait AppValidation { | |||
} | |||
) | |||
|
|||
def validateCanonicalAppUpdateAPI(enabledFeatures: Set[String]): Validator[AppUpdate] = forAll( | |||
def validateCanonicalAppUpdateAPI(enabledFeatures: Set[String], normalizationConfig: AppNormalization.Config): Validator[AppUpdate] = forAll( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use a defaultNetworkName: Option[String]
here. let's not mix normalization APIs into the validation code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to the migration code here https://github.com/mesosphere/marathon/blob/master/src/main/scala/mesosphere/marathon/storage/migration/MigrationTo15.scala#L63 it was not able to pass the Option[String]
directly. Any ideas here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, refactor some bits in the migration code: extract the network name logic into a separate def
that's reused by the normalization init code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already had an discussion regarding this issue. There is an explicit override
override def defaultNetworkName: Option[String] =
| env.vars.get(DefaultNetworkNameForMigratedApps).orElse(networkName).orElse(throw SerializationFailedException(
| MigrationFailedMissingNetworkEnvVar))
which throws an exception if this is is None. But None is a valid state in some cases afterwards. Therefore we decided to pass this not directly and go for a lazy implementation.
What about adding a trait ValidationConfig
which holds the enabledFeatures
and defaultNetworkName
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trait works. Or else a func that produces an Option[String]
(which would be even more minimal than a trait)
@@ -367,7 +371,7 @@ trait AppValidation { | |||
} | |||
) | |||
|
|||
def validateCanonicalAppAPI(enabledFeatures: Set[String]): Validator[App] = forAll( | |||
def validateCanonicalAppAPI(enabledFeatures: Set[String], normalizationConfig: AppNormalization.Config): Validator[App] = forAll( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto, Option[String]
@@ -194,7 +195,7 @@ trait PodsValidation { | |||
hostPorts.distinct.size == hostPorts.size | |||
} | |||
|
|||
def podValidator(enabledFeatures: Set[String], mesosMasterVersion: SemanticVersion): Validator[Pod] = validator[Pod] { pod => | |||
def podValidator(enabledFeatures: Set[String], mesosMasterVersion: SemanticVersion, defaultNetworkName: ScallopOption[String]): Validator[Pod] = validator[Pod] { pod => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please don't use scallop here, it's not needed. use a simple Option[String]
type instead. pretty sure that you can invoke .get
on a ScallopOption[T]
to get an Option[T]
(to pass in here)
@@ -211,6 +212,9 @@ trait PodsValidation { | |||
} | |||
pod.secrets is empty or (valid(secretValidator) and featureEnabled(enabledFeatures, Features.SECRETS)) | |||
pod.networks is valid(ramlNetworksValidator) | |||
pod.networks is isTrue[Seq[Network]]("network name must be specified when container network is selected") { nets => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this logic is the same for both apps and pods. perhaps extract into a NetworkValidation
class and NetworkValidationMessages
class (used by both app and pod validation), and use the static message field (instead of a literal string) for the validation error
val configWithDefaultNetworkName = AppNormalization.Configuration(Some("defaultNetworkName"), "mesos-bridge-name") | ||
implicit val basicValidator: Validator[App] = AppValidation.validateCanonicalAppAPI(Set.empty, config) | ||
implicit val withSecretsValidator: Validator[App] = AppValidation.validateCanonicalAppAPI(Set("secrets"), config) | ||
implicit val withDefaultNetworkNameValidator: Validator[App] = AppValidation.validateCanonicalAppAPI(Set.empty, configWithDefaultNetworkName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, redundant implicit types are strange here. it's not the OPs job to fix, but I'd like to suggest that we at least refrain from continuing the pattern: withDefaultNetworkNameValidator
should not be implicit.
Thanks for the review! I'll fix those comments over the weekend :-) |
10d17d6
to
e1655cc
Compare
@jdef @unterstein can you re-review please? I fixed all your comments PS: Sorry for the delay - holidays :-) |
@jdef @unterstein anything I can do to get this merged? :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, otherwise lgtm
ex.msg shouldBe NetworkNormalizationMessages.ContainerNetworkNameUnresolved | ||
val response = f.podsResource.create(podSpecJsonWithContainerNetworking.getBytes(), force = false, f.auth.request) | ||
response.getStatus shouldBe 422 | ||
response.getEntity.toString should include("Network name must be specified") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: reference NetworkValidationMessages.NetworkNameMustBeSpecified
instead of hard coding the text message
@jdef good point - fixed |
Thanks @alenkacz !
|
Throws validation exception instead of just NormalizationException when default network name is not specified