Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

App and pod validation errors for missing network name MARATHON-7398 #5432

Merged
merged 6 commits into from
Aug 21, 2017

Conversation

alenkacz
Copy link
Contributor

@alenkacz alenkacz commented Jul 2, 2017

Throws validation exception instead of just NormalizationException when default network name is not specified

Copy link
Contributor

@unterstein unterstein left a 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)
Copy link
Contributor

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.

Copy link
Contributor

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.

@unterstein unterstein requested a review from jdef July 3, 2017 16:12
@unterstein unterstein self-assigned this Jul 3, 2017
@unterstein
Copy link
Contributor

Hey @jdef,

when your back after US holidays, could you have a look, this would be awesome!

Thanks =)

Copy link
Contributor

@jdef jdef left a 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(
Copy link
Contributor

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

Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor

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 ?

Copy link
Contributor

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(
Copy link
Contributor

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 =>
Copy link
Contributor

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 =>
Copy link
Contributor

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)
Copy link
Contributor

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.

@alenkacz
Copy link
Contributor Author

alenkacz commented Jul 7, 2017

Thanks for the review! I'll fix those comments over the weekend :-)

@alenkacz
Copy link
Contributor Author

alenkacz commented Aug 2, 2017

@jdef @unterstein can you re-review please? I fixed all your comments

PS: Sorry for the delay - holidays :-)

@alenkacz
Copy link
Contributor Author

@jdef @unterstein anything I can do to get this merged? :-)

Copy link
Contributor

@jdef jdef left a 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")
Copy link
Contributor

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

@alenkacz
Copy link
Contributor Author

@jdef good point - fixed

@unterstein
Copy link
Contributor

Thanks @alenkacz !

    .  o ..                  
     o . o o.o                
          ...oo               
            __[]__          Shippin'  
         __|_o_o_o\__         it!
         \""""""""""/         
          \. ..  . /          
     ^^^^^^^^^^^^^^^^^^^^

@unterstein unterstein merged commit 6e13c9d into d2iq-archive:master Aug 21, 2017
@kensipe kensipe mentioned this pull request Sep 26, 2017
5 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants