-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97e88d5
commit f33ae30
Showing
21 changed files
with
368 additions
and
44 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
33 changes: 33 additions & 0 deletions
33
keel-core/src/main/kotlin/com/netflix/spinnaker/keel/IntentPolicy.kt
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,33 @@ | ||
/* | ||
* Copyright 2017 Netflix, Inc. | ||
* | ||
* 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 com.netflix.spinnaker.keel | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeInfo | ||
|
||
/** | ||
* A Policy can be attached to a single Intent, or applied globally via Keel configuration / dynamic admin API. These | ||
* classes are used to define additional behavior of how an Intent should behave under specific conditions, whether | ||
* an Intent should be applied given the condition of the managed system and/or Spinnaker state, and so-on. | ||
* | ||
* Matchers are primarily attached to policies only on Keel configuration / admin API usage, allowing a policy to be | ||
* applied globally, matching a subset of Intents. For example, an EnabledPolicy could be set with a falsey value, and | ||
* use Matchers to narrow by the PriorityMatcher so that only CRITICAL Priority Intents are enabled, across all | ||
* applications. | ||
*/ | ||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "kind") | ||
abstract class Policy { | ||
fun getId(): String = this.javaClass.simpleName | ||
} |
20 changes: 20 additions & 0 deletions
20
keel-core/src/main/kotlin/com/netflix/spinnaker/keel/IntentPriority.kt
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,20 @@ | ||
/* | ||
* Copyright 2017 Netflix, Inc. | ||
* | ||
* 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 com.netflix.spinnaker.keel | ||
|
||
enum class IntentPriority { | ||
CRITICAL, HIGH, NORMAL, LOW | ||
} |
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
23 changes: 23 additions & 0 deletions
23
keel-core/src/main/kotlin/com/netflix/spinnaker/keel/PolicyRepository.kt
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,23 @@ | ||
/* | ||
* Copyright 2017 Netflix, Inc. | ||
* | ||
* 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 com.netflix.spinnaker.keel | ||
|
||
interface PolicyRepository { | ||
|
||
fun findAll(): List<Policy> | ||
fun upsert(policy: Policy) | ||
fun delete(id: String) | ||
} |
68 changes: 68 additions & 0 deletions
68
keel-core/src/main/kotlin/com/netflix/spinnaker/keel/matcher/Matcher.kt
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 2017 Netflix, Inc. | ||
* | ||
* 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 com.netflix.spinnaker.keel.matcher | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeInfo | ||
import com.fasterxml.jackson.annotation.JsonTypeName | ||
import com.netflix.spinnaker.keel.ApplicationAwareIntentSpec | ||
import com.netflix.spinnaker.keel.Intent | ||
import com.netflix.spinnaker.keel.IntentPriority | ||
import com.netflix.spinnaker.keel.IntentSpec | ||
import com.netflix.spinnaker.keel.policy.PriorityPolicy | ||
|
||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "kind") | ||
interface Matcher { | ||
fun match(intent: Intent<IntentSpec>): Boolean | ||
} | ||
|
||
@JsonTypeName("All") | ||
class AllMatcher : Matcher { | ||
override fun match(intent: Intent<IntentSpec>): Boolean { | ||
return true | ||
} | ||
} | ||
|
||
@JsonTypeName("Application") | ||
class ApplicationMatcher(val expected: String) : Matcher { | ||
override fun match(intent: Intent<IntentSpec>) = | ||
when (intent.spec) { | ||
is ApplicationAwareIntentSpec -> intent.spec.application == expected | ||
else -> false | ||
} | ||
} | ||
|
||
enum class PriorityMatcherScope { | ||
EQUAL, EQUAL_GT, EQUAL_LT | ||
} | ||
|
||
// TODO rz - allow defaulting intents if the priority policy isn't present | ||
@JsonTypeName("Priority") | ||
class PriorityMatcher( | ||
private val level: IntentPriority, | ||
private val scope: PriorityMatcherScope | ||
) : Matcher { | ||
override fun match(intent: Intent<IntentSpec>) | ||
= intent.policies | ||
.filterIsInstance<PriorityPolicy>() | ||
.filter { p -> | ||
when (scope) { | ||
PriorityMatcherScope.EQUAL -> p.priority == level | ||
PriorityMatcherScope.EQUAL_GT -> p.priority >= level | ||
PriorityMatcherScope.EQUAL_LT -> p.priority <= level | ||
} | ||
} | ||
.count() > 0 | ||
} |
34 changes: 34 additions & 0 deletions
34
keel-core/src/main/kotlin/com/netflix/spinnaker/keel/memory/MemoryPolicyRepository.kt
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,34 @@ | ||
/* | ||
* Copyright 2017 Netflix, Inc. | ||
* | ||
* 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 com.netflix.spinnaker.keel.memory | ||
|
||
import com.netflix.spinnaker.keel.Policy | ||
import com.netflix.spinnaker.keel.PolicyRepository | ||
|
||
class MemoryPolicyRepository : PolicyRepository { | ||
|
||
private val policies: MutableMap<String, Policy> = mutableMapOf() | ||
|
||
override fun findAll() = policies.entries.map { it.value } | ||
|
||
override fun upsert(policy: Policy) { | ||
policies.put(policy.getId(), policy) | ||
} | ||
|
||
override fun delete(id: String) { | ||
policies.remove(id) | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
keel-core/src/main/kotlin/com/netflix/spinnaker/keel/policy/policies.kt
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,60 @@ | ||
/* | ||
* Copyright 2017 Netflix, Inc. | ||
* | ||
* 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 com.netflix.spinnaker.keel.policy | ||
|
||
import com.fasterxml.jackson.annotation.JsonTypeName | ||
import com.netflix.spinnaker.keel.IntentPriority | ||
import com.netflix.spinnaker.keel.Policy | ||
|
||
@JsonTypeName("Enabled") | ||
data class EnabledPolicy( | ||
val flag: Boolean = true | ||
) : Policy() | ||
|
||
/** | ||
* PriorityPolicy can be provided to an Intent to assign criticality. This allows end-users to self-define how mandatory | ||
* certain intents are compared to others. | ||
* | ||
* TODO rz - Allow users to self-manage priority of intents inside of their own defined buckets (like, by team). | ||
*/ | ||
@JsonTypeName("Priority") | ||
data class PriorityPolicy( | ||
val priority: IntentPriority = IntentPriority.NORMAL | ||
) : Policy() | ||
|
||
//@JsonTypeName("Delivery") | ||
//data class DeliveryPolicy( | ||
// val backoffMultiplier: Float, | ||
// val convergeRate: Duration | ||
//) : Policy() | ||
// | ||
//// TODO rz - kinds: "PreviousStateRollback" "RunOrchestrationRollback" "RunPipelineRollback" etc | ||
//@JsonTypeName("Rollback") | ||
//data class RollbackPolicy( | ||
//) : Policy() | ||
// | ||
//@JsonTypeName("ExecutionWindow") | ||
//data class ExecutionWindowPolicy( | ||
// override val matchers: MutableList<Matcher> = mutableListOf() | ||
//) : Policy() | ||
|
||
// TODO rz - Allow people to define if they're notified on changes, failures (how to configure notification channels?) | ||
// Probably warrants a keel-echo module and just drop this in there. | ||
//@JsonTypeName("Notification") | ||
//data class NotificationPolicy( | ||
// val changes: Boolean, | ||
// val failures: Boolean | ||
//) : Policy() |
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
Oops, something went wrong.