API References
Package exports
__main__
The main module provides the executable entrypoint for oper8
add_command(subparsers, cmd)
Add the subparser and set up the default fun call
Source code in oper8/__main__.py
79 80 81 82 83 84 85 86 87 88 |
|
add_library_config_args(parser, config_obj=None, path=None)
Automatically add args for all elements of the library config
Source code in oper8/__main__.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
main()
The main module provides the executable entrypoint for oper8
Source code in oper8/__main__.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
update_library_config(args, setters)
Update the library config values based on the parsed arguments
Source code in oper8/__main__.py
69 70 71 72 73 74 75 76 |
|
cmd
This module holds all of the command classes for oper8's main entrypoint
base
Base class for all oper8 commands
CmdBase
Bases: ABC
Source code in oper8/cmd/base.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
add_subparser(subparsers)
abstractmethod
Add this command's argument parser subcommand
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subparsers
|
_SubParsersAction
|
The subparser section for the central main parser |
required |
Returns:
Name | Type | Description |
---|---|---|
subparser |
ArgumentParser
|
The configured parser for this command |
Source code in oper8/cmd/base.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
cmd(args)
abstractmethod
Execute the command with the parsed arguments
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args
|
Namespace
|
The parsed command line arguments |
required |
Source code in oper8/cmd/base.py
29 30 31 32 33 34 35 |
|
check_heartbeat
This is the main entrypoint command for running the operator
CheckHeartbeatCmd
Bases: CmdBase
Source code in oper8/cmd/check_heartbeat.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
cmd(args)
Run command to validate a health check file
Source code in oper8/cmd/check_heartbeat.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
run_operator_cmd
This is the main entrypoint command for running the operator
RunOperatorCmd
Bases: CmdBase
Source code in oper8/cmd/run_operator_cmd.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
setup_vcs_cmd
CLI command for setting up a VCS version repo
SetupVCSCmd
Bases: CmdBase
Source code in oper8/cmd/setup_vcs_cmd.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
add_subparser(subparsers)
Add the subparser for this command
Source code in oper8/cmd/setup_vcs_cmd.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
component
Component base class for building larger abstractions off of
Component
Bases: Node
, ABC
This file defines the top-level interface for a "Component" in the deployment ecosystem. Each Component will ultimately resolve to a Node in the deployment execution graph which can be atomically rendered, deployed, verified, and if needed reverted.
Source code in oper8/component.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 |
|
managed_objects
property
The list of managed objects that this Component currently knows about. If called before rending, this will be an empty list, so it will always be iterable.
Returns:
Name | Type | Description |
---|---|---|
managed_objects |
List[ManagedObject]
|
List[ManagedObject] The list of known managed objects |
__build_lazy_charts(session)
Delegate to the child implementation of build_chart for lazy chart construction.
Source code in oper8/component.py
452 453 454 455 456 |
|
__gather_resources(session)
This is a helper for __render which handles converting resource objects into a list of dictionaries.
Source code in oper8/component.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 |
|
__init__(session, disabled=False)
Construct with the session for this deployment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The session that this component will belong to |
required |
disabled
|
bool
|
bool Whether or not this component is disabled |
False
|
Source code in oper8/component.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
__render(session)
This is the primary implementation for rendering objects into self.managed_objects
Source code in oper8/component.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
|
add_dependency(session, *components, verify_function=None)
This add_dependency function sets up a dependency between this component
and a list of other components. To add a dependency between resources inside
this component use resource.add_dependency
Args:
session: Session
The current resource session
*components: Components
Any number of components to be added as a dependency
verify_function: Optional[verify_function]
An Optional callable function of the form def verify(session) -> bool:
to use to verify that the dependency has been satisfied. This
will be used to block deployment of the component beyond
requiring that the upstream has been deployed successfully.
Source code in oper8/component.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
add_resource(name, obj, verify_function=None, deploy_method=DeployMethod.DEFAULT)
The add_resource function allows the derived class to add resources to this component to later be rendered
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
str The name of the resource in the Graph |
required |
obj
|
Any
|
Any An object or dict which can be manipulated into a dict representation of the kubernetes resource |
required |
Source code in oper8/component.py
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
|
build_chart(session)
The build_chart function allows the derived class to add child Charts lazily so that they can take advantage of post-initialization information.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The current deploy session |
required |
Source code in oper8/component.py
102 103 104 105 106 107 108 109 110 |
|
deploy(session)
Deploy the component
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session The current reconciliation session |
required |
Returns:
Name | Type | Description |
---|---|---|
success |
bool True on successful application of the kub state (not programmatic verification), False otherwise |
Source code in oper8/component.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
|
disable(session)
Disable the component
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session The current reconciliation session |
required |
Returns:
Name | Type | Description |
---|---|---|
success |
bool True on successful application of the kub state (not programmatic verification), False otherwise |
Source code in oper8/component.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
get_name()
classmethod
Override get_name to support class attribute
Source code in oper8/component.py
356 357 358 359 |
|
name()
All Components must implement a name class attribute
Source code in oper8/component.py
40 41 42 |
|
render_chart(session)
This will be invoked by the parent Application to build and render the individual component's chart
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session The session for this reconciliation |
required |
Source code in oper8/component.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
to_config(session)
Render the component and return it as an AttrDict, mainly useful for testing :return: AttrDict of the rendered component
Source code in oper8/component.py
301 302 303 304 305 306 307 308 309 310 |
|
to_dict(session)
Render the component and return it as a Dictionary, mainly useful for testing :return: Dictionary of the rendered component
Source code in oper8/component.py
292 293 294 295 296 297 298 299 |
|
to_file(session)
Render the component to disk and return the rendered file path :return: str path to rendered file
Source code in oper8/component.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
|
update_object_definition(session, internal_name, resource_definition)
Allow children to inject arbitrary object mutation logic for individual managed objects
The base implementation simply returns the given definition as a passthrough
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The session for this reconciliation |
required |
internal_name
|
str
|
str The internal name of the object to update |
required |
resource_definition
|
dict
|
dict The dict representation of the resource to modify |
required |
Returns:
Name | Type | Description |
---|---|---|
resource_definition |
dict The dict representation of the resource with any modifications applied |
Source code in oper8/component.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
verify(session)
The verify function will run any necessary testing and validation that the component needs to ensure that rollout was successfully completed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session The current reconciliation session |
required |
Returns:
Name | Type | Description |
---|---|---|
success |
bool True on successful deployment verification, False on failure conditions |
Source code in oper8/component.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
config
Base operator config module. The config here is only used as a baseline bootup config. All application-specific config must come from the app_config.
config
This module just loads config at import time and does the initial log config
validation
Module to validate values in a loaded config
get_invalid_params(config, validation_config)
Get a list of any params that are invalid
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
Config
|
aconfig.Config The parsed config with any override values |
required |
validation_config
|
Config
|
aconfig.Config The parallel config holding validation setup |
required |
Returns:
Name | Type | Description |
---|---|---|
invalid_params |
List[str]
|
List[str] A list of all string keys for parameters that fail validation |
Source code in oper8/config/validation.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
constants
Shared module to hold constant values for the library
controller
The Controller class manages a collection of Components and associates them with a CustomResource in the cluster.
Controller
Bases: ABC
This class represents a controller for a single kubernetes custom resource kind. Its primary functionality is to perform a reconciliation of a given CR manifest for an instance of the resource kind against the current state of the cluster. To accomplish this, its reconciliation logic is:
- Construct a Directed Acyclic Graph of all Components that this kind needs to manage.
- Execute the Graph in dependency order where each node of the graph first renders the manifests for all kubernetes resources managed by the Component, then applies them to the cluster.
- Execute a secondary Graph with verification logic for each Component, terminating verification for downstream nodes if any node is not yet verified.
To do this, the main operations of the class are to construct a DAG of Components, then walk them through the primary lifecycle phases:
- Run the Component's deploy() function to completion and verify that the actual deployment operations succeeded
- Run the Component's verify() function to run component-specific tests that will verify if the deployment is rolled out in a successful state
Source code in oper8/controller.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
|
__init__(config_defaults=None)
The constructor sets up all of the properties of the controller which are constant across reconciliations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config_defaults
|
Optional[Config]
|
Optional[aconfig.Config] Default values for the backend controller config |
None
|
Source code in oper8/controller.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
__str__()
classmethod
Stringify with the GVK
Source code in oper8/controller.py
108 109 110 111 |
|
after_deploy(session)
This allows children to inject logic that will run when the controller has finished deploying all components, but not necessarily verifying all of them. The default behavior is a no-op.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The current reconciliation session |
required |
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool True if custom hook code executed successfully and lifecycle should continue |
Source code in oper8/controller.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
after_deploy_unsuccessful(session, failed)
This allows children to inject logic that will run when the controller has failed or could not finish deploying all components. The default behavior is a no-op.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The current reconciliation session |
required |
failed
|
bool
|
bool Indicator of whether or not the termination was a failure |
required |
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool True if custom hook code executed successfully and lifecycle should continue |
Source code in oper8/controller.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
after_verify(session)
This allows children to inject logic that will run when the controller has finished verifying all components. The default behavior is a no-op.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The current reconciliation session |
required |
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool True if custom hook code executed successfully and lifecycle should continue |
Source code in oper8/controller.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|
after_verify_unsuccessful(session, failed)
This allows children to inject logic that will run when the controller has finished deploying all components but failed to verify. The default behavior is a no-op.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The current reconciliation session |
required |
failed
|
bool
|
bool Indicator of whether or not the termination was a failure |
required |
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool True if custom hook code executed successfully and lifecycle should continue |
Source code in oper8/controller.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
finalize_components(session)
When performing a finalizer operation, this function will be called to perform custom finalizer logic for this Controller.
Error Semantics: Child classes should throw ConfigError if config is not valid and include the portion of config where the problem occurred.
This method is not abstract since the standard controller usecase
does not require finalizing
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The current session containing the per-event configs |
required |
Source code in oper8/controller.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
finalizer()
The finalizer used by this Controller
Source code in oper8/controller.py
77 78 79 80 81 82 |
|
get_config_defaults()
This function allows children to override the default values for the session config. This value can also be set via the controllers init function.
Source code in oper8/controller.py
283 284 285 286 287 |
|
get_cr_manifest_defaults()
This allows children to provide default values for their cr_manifest that will be injected where no override is provided in the user-provided cr_manifest.
Returns:
Name | Type | Description |
---|---|---|
cr_manifest_defaults |
Union[dict, Config]
|
Union[dict, aconfig.Config] The cr defaults. Raw dicts will be converted to Config objects. |
Source code in oper8/controller.py
270 271 272 273 274 275 276 277 278 279 280 281 |
|
group()
The apiVersion group for the resource this controller manages
Source code in oper8/controller.py
65 66 67 |
|
has_finalizer()
If the derived class has an implementation of finalize_components, it has a finalizer and can be registered for finalize events
Source code in oper8/controller.py
84 85 86 87 88 89 |
|
kind()
The kind for the resource this controller manages
Source code in oper8/controller.py
73 74 75 |
|
run_reconcile(session, is_finalizer=False)
Perform a reconciliation iteration for this controller on given a session. This function should only be called once per session. The general logic for a controller reconcile is as follows:
- Set up the set of Components and their dependencies that will be managed in this reconciliation based on the CR and config
- Invoke the rollout to render each component and apply it to the cluster (if not in dry-run), then verify the DAG of components
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The full structured content of the CR manifest for this operand |
required |
is_finalizer
|
bool
|
bool If true, the logic in finalize_components is run, otherwise the logic in setup_components is called |
False
|
Returns:
Name | Type | Description |
---|---|---|
result |
CompletionState
|
ReconciliationResult The result of reconcile |
Source code in oper8/controller.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
|
setup_components(session)
abstractmethod
Given the session for an individual reconciliation, construct the set of Components that will be deployed.
Error Semantics: Child classes should throw ConfigError if config is not valid and include the portion of config where the problem occurred.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The current session containing the per-event configs |
required |
Source code in oper8/controller.py
118 119 120 121 122 123 124 125 126 127 128 129 |
|
should_requeue(session)
should_requeue determines if current reconcile request should be re-queued.
Children can override default implementation to provide custom logic. Default implementation re-queues the request if the reconciling CR status hasn't been reached stable state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The current reconciliation session |
required |
Returns:
Name | Type | Description |
---|---|---|
requeue |
bool
|
bool True if the reconciliation request should be re-queued |
config |
Optional[RequeueParams]
|
RequeueParams Parameters of requeue request. Can be None if requeue is False. |
Source code in oper8/controller.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
|
version()
The apiVersion version for the resource this controller manages
Source code in oper8/controller.py
69 70 71 |
|
dag
Package exports
completion_state
CompletionState holds info about how a DAG Runner completes
CompletionState
This class holds the definition of a CompletionState which manages all the information about how the nodes in a rollout Runner terminated
Source code in oper8/dag/completion_state.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
__init__(verified_nodes=None, unverified_nodes=None, failed_nodes=None, unstarted_nodes=None, exception=None)
Construct with each node set
Source code in oper8/dag/completion_state.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
deploy_completed()
Determine if the dag completed all nodes through to the deploy step
NOTE: An empty node set is considered completed
Returns:
Name | Type | Description |
---|---|---|
completed |
bool
|
bool True if there are no failed nodes and no unstarted nodes |
Source code in oper8/dag/completion_state.py
85 86 87 88 89 90 91 92 93 94 95 |
|
failed()
Determine if any of the nodes failed
Returns:
Name | Type | Description |
---|---|---|
failed |
bool
|
bool True if there are any nodes in the failed state or there is a fatal error |
Source code in oper8/dag/completion_state.py
115 116 117 118 119 120 121 122 123 |
|
verify_completed()
Determine if the dag completed all nodes through to the verification step
NOTE: An empty node set is considered verified
Returns:
Name | Type | Description |
---|---|---|
completed |
bool
|
bool True if there are no nodes found outside of the verified_nodes and there is no exception in the termination state |
Source code in oper8/dag/completion_state.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
graph
Graph holds information about a Directed Acyclic Graph
Graph
Class for representing an instance of a Graph. Handles adding and removing nodes as well as graph functions like flattening
Source code in oper8/dag/graph.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
node_dict
property
Dictionary of all node names and their nodes
root
property
The root node of the Graph
__iter__()
Iterate over all child nodes
Source code in oper8/dag/graph.py
126 127 128 |
|
add_node(node)
Add node to graph Args: node: Node The node to be added to the Dag.
Source code in oper8/dag/graph.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
|
add_node_dependency(parent_node, child_node, edge_fn=None)
Add dependency or "edge" to graph between two nodes. This is the same as doing parent_node.add_dependency(child_node) Args: parent_node: Node The parent or dependent node aka the node that must wait child_node: Node The child or dependency node aka the node that must be deployed first edge_fn:
Source code in oper8/dag/graph.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
empty()
Check if a graph is empty
Source code in oper8/dag/graph.py
101 102 103 |
|
get_all_nodes()
Get list of all nodes
Source code in oper8/dag/graph.py
93 94 95 |
|
get_node(name)
Get the node with name
Source code in oper8/dag/graph.py
89 90 91 |
|
has_node(node)
Check if node is in graph
Source code in oper8/dag/graph.py
97 98 99 |
|
topology()
Get a list of nodes in deployment order
Source code in oper8/dag/graph.py
107 108 109 110 111 |
|
node
This module contains a collection of classes for implementing nodes of a Graph
Node
Class for representing a node in the Graph
Source code in oper8/dag/node.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
__eq__(obj)
Compare and sort nodes by name
Source code in oper8/dag/node.py
95 96 97 98 99 |
|
__init__(name=None, data=None)
Construct a new Node
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
Optional[str]
|
Optional[str] The name of the node |
None
|
data
|
Optional[Any]
|
Optional[Any] Any data that should be stored with the node |
None
|
Source code in oper8/dag/node.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
add_child(node, edge_data=None)
Add edge from self to node with optional edge data
Source code in oper8/dag/node.py
29 30 31 32 33 |
|
dfs(node, visited=None)
Function to determine if their is a path between two nodes. Used in acyclic check
Source code in oper8/dag/node.py
80 81 82 83 84 85 86 87 88 89 90 91 92 |
|
get_children()
Accessor for all children
Source code in oper8/dag/node.py
58 59 60 |
|
get_data()
Accessor for specific child
Source code in oper8/dag/node.py
46 47 48 |
|
get_name()
Accessor for specific child
Source code in oper8/dag/node.py
50 51 52 |
|
has_child(node)
Accessor for specific child
Source code in oper8/dag/node.py
54 55 56 |
|
remove_child(node)
Remove child node from self
Source code in oper8/dag/node.py
35 36 37 38 |
|
set_data(data)
Mutator for node data
Source code in oper8/dag/node.py
40 41 42 |
|
topology()
Function to get an ordered topology of a node's children
Source code in oper8/dag/node.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
ResourceNode
Bases: Node
Class for representing a kubernetes resource in the Graph with a function for verifying said resource
Source code in oper8/dag/node.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
api_group
property
The kubernetes apiVersion group name without the schema version
api_version
property
The full kubernetes apiVersion
deploy_method
property
The resource manifest
kind
property
The resource kind
manifest
property
The resource manifest
metadata
property
The full resource metadata dict
name
property
The resource metadata.name
verify_function
property
The resource manifest
add_dependency(node)
Add a child dependency to this node
Source code in oper8/dag/node.py
178 179 180 |
|
runner
This module contains a collection of classes for executing functions along a DAG
DagHaltError
Bases: Exception
Custom exception used to indicate that a Runner execution should halt
Source code in oper8/dag/runner.py
315 316 317 318 319 320 321 322 323 324 325 |
|
NonThreadPoolExecutor
Bases: Executor
This "pool" implements the Executor interfaces, but runs without any threads. This is used when running a Runner without cocurrency
Source code in oper8/dag/runner.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
__init__(*_, **__)
Swallow constructor args so that it can match ThreadPoolExecutor
Source code in oper8/dag/runner.py
299 300 301 |
|
shutdown(*_, **__)
staticmethod
Nothing to do since this is not a real pool
Source code in oper8/dag/runner.py
310 311 312 |
|
submit(fn, /, *args, **kwargs)
staticmethod
Run the function immediately and return a pre-completed Future
Source code in oper8/dag/runner.py
303 304 305 306 307 308 |
|
Runner
This is a very simple "keep running until done" Runner executor which uses a ThreadPoolExecutor to allow non-blocking calls to execute in parallel.
Source code in oper8/dag/runner.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
|
__init__(name='', threads=None, graph=None, default_function=None, poll_time=0.05, verify_upstream=True)
Construct a Runner which will manage the execution of a single Graph
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
str String name that can be used for logging to differentiate deploy and verify Graph executions |
''
|
threads
|
Optional[int]
|
Optional[int] Number of threads to use. If not given, the default behavior of ThreadPoolExecutor is to use the number of available cores. |
None
|
graph
|
Optional[Graph]
|
Optional[Graph] Existing graph to use, if not supplied an empty graph is created |
None
|
default_function
|
Optional[Callable[[Node], bool]]
|
Optional[Callable[["Node"],None]]=None Function that will be called on node run if specific function is not provided |
None
|
poll_time
|
float
|
float How often to check runner status |
0.05
|
verify_upstream
|
bool
|
bool Conditional to control whether to check a nodes upstream via its edge function |
True
|
Source code in oper8/dag/runner.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
completion_state()
Get the state of which nodes completed and which failed
Returns:
Name | Type | Description |
---|---|---|
completion_state |
CompletionState The state holding the full view of the termination state of each node |
Source code in oper8/dag/runner.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
disable_node(node)
Function to disable a node in the graph. This will skip the node in runner without changing the graph
Source code in oper8/dag/runner.py
89 90 91 92 93 94 95 96 97 |
|
enable_node(node)
Function to reenable a node after it was disabled by Runner.disable_node
Source code in oper8/dag/runner.py
99 100 101 102 103 104 105 106 |
|
run()
Run the Runner! This will continue until the graph has run to completion or halted due to an error.
Source code in oper8/dag/runner.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
decorator
Decorator for making the authoring of "pure" components easier
component(name)
The @component decorator is the primary entrypoint for creating an oper8.Component. It ensures the wrapped type's interface matches the expected Component interface, including the "name" class attribute.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
str The name string will be set as the class property for the wrapped class |
required |
Returns:
Name | Type | Description |
---|---|---|
decorator |
Callable[[Type], Type]
|
Callable[[Type[Component]], Type[Component]] The decorator function that will be invoked on construction of decorated classes |
Source code in oper8/decorator.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
controller(group, version, kind, finalizer=None, extra_properties=None)
The @controller decorator is the primary entrypoint for creating an oper8.Controller. It ensures the wrapped type's interface matches the required Controller interface, including class properties.
The extra_properties
argument is an entrypoint for loosely coupled
Controller-specific configuration that is tied to the specific WatchManager implementation being used. The current list of useful properties is:
- disable_vcs: This can be used to tell the AnsibleWatchManager that the Controller will not use ansible-vcs, even if other Controllers managed by the same operator do.
- pwm_filters: This can be used to tell the PythonWatchManager of any additional watch filters. If value is a list then the filters are added to all watches including dependent watches. If value is a dict than it expects the keys to be the resource global id with the values being a list of filters for that resource
- pwm_subsystems: This can be used to tell the PythonWatchManager of any subsystem relations. This allows a "subsystem" controller to be ran during the reconciliation of another similar to the DryRunWatchManager
Parameters:
Name | Type | Description | Default |
---|---|---|---|
group
|
str
|
str The apiVersion group for the resource this controller manages |
required |
version
|
str
|
str The apiVersion version for the resource this controller manages |
required |
kind
|
str
|
str The kind for the resource this controller manages |
required |
extra_properties
|
Optional[Dict[str, any]]
|
Optional[Dict[str, any]] Extra properties that should be defined as class-properties for this controller |
None
|
Returns:
Name | Type | Description |
---|---|---|
decorator |
Callable[[Type[Controller]], Type[Controller]]
|
Callable[[Type[Controller]], Type[Controller]] The decorator function that will be invoked on construction of decorated classes |
Source code in oper8/decorator.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
deploy_manager
The DeployManager is the abstraction in charge of interacting with the kubernetes cluster to deploy, look up, and delete resources.
base
This defines the base class for all DeployManager types.
DeployManagerBase
Bases: ABC
Base class for deploy managers which will be responsible for carrying out the actual deploy of an Application/Component.
Source code in oper8/deploy_manager/base.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
deploy(resource_definitions, manage_owner_references=True, method=DeployMethod.DEFAULT)
abstractmethod
The deploy function ensures that the resources defined in the list of definitions are deployed in the cluster.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource_definitions
|
List[dict]
|
list(dict) List of resource object dicts to apply to the cluster |
required |
manage_owner_references
|
bool
|
bool If true, ownerReferences for the parent CR will be applied to the deployed object |
True
|
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool Whether or not the deploy succeeded |
changed |
bool
|
bool Whether or not the deployment resulted in changes |
Source code in oper8/deploy_manager/base.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
disable(resource_definitions)
abstractmethod
The disable function ensures that the resources defined in the list of definitions are deleted from the cluster
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource_definitions
|
List[dict]
|
list(dict) List of resource object dicts to apply to the cluster |
required |
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool Whether or not the delete succeeded |
changed |
bool
|
bool Whether or not the delete resulted in changes |
Source code in oper8/deploy_manager/base.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
filter_objects_current_state(kind, namespace=None, api_version=None, label_selector=None, field_selector=None)
abstractmethod
The filter_objects_current_state function fetches a list of objects that match either/both the label or field selector Args: kind: str The kind of the object to fetch namespace: str The namespace to search for the object api_version: str The api_version of the resource kind to fetch label_selector: str The label_selector to filter the resources field_selector: str The field_selector to filter the resources
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool Whether or not the state fetch operation succeeded |
current_state |
List[dict]
|
List[dict] A list of dict representations for the objects configuration, or an empty list if no objects match |
Source code in oper8/deploy_manager/base.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
get_object_current_state(kind, name, namespace=None, api_version=None)
abstractmethod
The get_current_objects function fetches the current state of a given object by name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kind
|
str
|
str The kind of the object to fetch |
required |
name
|
str
|
str The full name of the object to fetch |
required |
namespace
|
Optional[str]
|
str The namespace to search for the object |
None
|
api_version
|
Optional[str]
|
str The api_version of the resource kind to fetch |
None
|
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool Whether or not the state fetch operation succeeded |
current_state |
dict
|
dict or None The dict representation of the current object's configuration, or None if not present |
Source code in oper8/deploy_manager/base.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
set_status(kind, name, namespace, status, api_version=None)
abstractmethod
Set the status for an object managed by oper8
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kind
|
str
|
str The kind of the object ot fetch |
required |
name
|
str
|
str The full name of the object to fetch |
required |
namespace
|
Optional[str]
|
Optional[str] The namespace to search for the object. If None search cluster wide |
required |
status
|
dict
|
dict The status object to set onto the given object |
required |
api_version
|
Optional[str]
|
str The api_version of the resource to update |
None
|
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool Whether or not the state fetch operation succeeded |
changed |
bool
|
bool Whether or not the status update resulted in a change |
Source code in oper8/deploy_manager/base.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
watch_objects(kind, api_version=None, namespace=None, name=None, label_selector=None, field_selector=None, resource_version=None)
abstractmethod
The watch_objects function listens for changes in the cluster and returns a stream of KubeWatchEvents
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kind
|
str
|
str The kind of the object to fetch |
required |
namespace
|
Optional[str]
|
str The namespace to search for the object |
None
|
name
|
Optional[str]
|
str The name to search for the object |
None
|
api_version
|
Optional[str]
|
str The api_version of the resource kind to fetch |
None
|
label_selector
|
Optional[str]
|
str The label_selector to filter the resources |
None
|
field_selector
|
Optional[str]
|
str The field_selector to filter the resources |
None
|
resource_version
|
Optional[str]
|
str The resource_version the resource must be newer than |
None
|
Returns:
Name | Type | Description |
---|---|---|
watch_stream |
Iterator[KubeWatchEvent]
|
Generator[KubeWatchEvent] A stream of KubeWatchEvents generated while watching |
Source code in oper8/deploy_manager/base.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
dry_run_deploy_manager
The DryRunDeployManager implements the DeployManager interface but does not actually interact with the cluster and instead holds the state of the cluster in a local map.
DryRunDeployManager
Bases: DeployManagerBase
Deploy manager which doesn't actually deploy!
Source code in oper8/deploy_manager/dry_run_deploy_manager.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 |
|
__init__(resources=None, owner_cr=None, strict_resource_version=False, generate_resource_version=True)
Construct with a static value to use for whether or not the functions should report change.
Source code in oper8/deploy_manager/dry_run_deploy_manager.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
register_finalizer(api_version, kind, callback, namespace='', name='')
Register a callback to call on deletion events on a given api_version/kind
Source code in oper8/deploy_manager/dry_run_deploy_manager.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
|
register_watch(api_version, kind, callback, namespace='', name='')
Register a callback to watch for deploy events on a given api_version/kind
Source code in oper8/deploy_manager/dry_run_deploy_manager.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
|
watch_objects(kind, api_version=None, namespace=None, name=None, label_selector=None, field_selector=None, resource_version=None, timeout=15, **kwargs)
Watch the DryRunDeployManager for resource changes by registering callbacks
Source code in oper8/deploy_manager/dry_run_deploy_manager.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
kube_event
Helper module to define shared types related to Kube Events
KubeEventType
Bases: Enum
Enum for all possible kubernetes event types
Source code in oper8/deploy_manager/kube_event.py
19 20 21 22 23 24 |
|
KubeWatchEvent
dataclass
DataClass containing the type, resource, and timestamp of a particular event
Source code in oper8/deploy_manager/kube_event.py
27 28 29 30 31 32 33 34 |
|
openshift_deploy_manager
This DeployManager is responsible for delegating cluster operations to the openshift library. It is the one that will be used when the operator is running in the cluster or outside the cluster making live changes.
OpenshiftDeployManager
Bases: DeployManagerBase
This DeployManager uses the openshift DynamicClient to interact with the cluster
Source code in oper8/deploy_manager/openshift_deploy_manager.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 |
|
client
property
Lazy property access to the client
__init__(manage_ansible_status=False, owner_cr=None)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
manage_ansible_status
|
bool
|
bool If true, oper8 will emulate the status management done natively by ansible based on the readiness values of oper8's native status management |
False
|
owner_cr
|
Optional[dict]
|
Optional[dict] The dict content of the CR that triggered this reconciliation. If given, deployed objects will have an ownerReference added to assign ownership to this CR instance. |
None
|
Source code in oper8/deploy_manager/openshift_deploy_manager.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
deploy(resource_definitions, manage_owner_references=True, retry_operation=True, method=DeployMethod.DEFAULT, **_)
Deploy using the openshift client
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource_definitions
|
List[dict]
|
list(dict) List of resource object dicts to apply to the cluster |
required |
manage_owner_references
|
bool
|
bool If true, ownerReferences for the parent CR will be applied to the deployed object |
True
|
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool True if deploy succeeded, False otherwise |
changed |
bool
|
bool Whether or not the deployment resulted in changes |
Source code in oper8/deploy_manager/openshift_deploy_manager.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
disable(resource_definitions)
The disable process is the same as the deploy process, but the child module params are set to 'state: absent'
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource_definitions
|
List[dict]
|
list(dict) List of resource object dicts to apply to the cluster |
required |
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool True if deploy succeeded, False otherwise |
changed |
bool
|
bool Whether or not the delete resulted in changes |
Source code in oper8/deploy_manager/openshift_deploy_manager.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
filter_objects_current_state(kind, namespace=None, api_version=None, label_selector=None, field_selector=None)
The filter_objects_current_state function fetches a list of objects that match either/both the label or field selector Args: kind: str The kind of the object to fetch namespace: str The namespace to search for the object api_version: str The api_version of the resource kind to fetch label_selector: str The label_selector to filter the resources field_selector: str The field_selector to filter the resources
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool Whether or not the state fetch operation succeeded |
current_state |
List[dict]
|
List[dict] A list of dict representations for the objects configuration, or an empty list if no objects match |
Source code in oper8/deploy_manager/openshift_deploy_manager.py
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
|
get_object_current_state(kind, name, namespace=None, api_version=None)
The get_current_objects function fetches the current state using calls directly to the api client
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kind
|
str
|
str The kind of the object ot fetch |
required |
name
|
str
|
str The full name of the object to fetch |
required |
namespace
|
Optional[str]
|
Optional[str] The namespace to search for the object or None for no namespace |
None
|
api_version
|
Optional[str]
|
Optional[str] The api_version of the resource kind to fetch |
None
|
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool Whether or not the state fetch operation succeeded |
current_state |
dict
|
dict or None The dict representation of the current object's configuration, or None if not present |
Source code in oper8/deploy_manager/openshift_deploy_manager.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
|
set_status(kind, name, namespace, status, api_version=None)
Set the status in the cluster manifest for an object managed by this operator
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kind
|
str
|
str The kind of the object ot fetch |
required |
name
|
str
|
str The full name of the object to fetch |
required |
namespace
|
Optional[str]
|
Optional[str] The namespace to search for the object. |
required |
status
|
dict
|
dict The status object to set onto the given object |
required |
api_version
|
Optional[str]
|
Optional[str] The api_version of the resource to update |
None
|
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool Whether or not the status update operation succeeded |
changed |
bool
|
bool Whether or not the status update resulted in a change |
Source code in oper8/deploy_manager/openshift_deploy_manager.py
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
|
owner_references
This module holds common functionality that the DeployManager implementations can use to manage ownerReferences on deployed resources
update_owner_references(deploy_manager, owner_cr, child_obj)
Fetch current ownerReferences and merge a reference for this CR into the child object
Source code in oper8/deploy_manager/owner_references.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
replace_utils
This file contains common utilities for detecting if a replace operation is required for a resource
modified_lists(current_manifest, desired_manifest, in_list=False)
Helper function to check if there are any differences in the lists of the desired manifest. This is required because Kubernetes combines lists which is often not the desired use
Source code in oper8/deploy_manager/replace_utils.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
modified_value_from(current_manifest, desired_manifest)
Helper function to check if a manifest switched from value to valueFrom. These are mutually exclusive thus they require a replace command.
Source code in oper8/deploy_manager/replace_utils.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
requires_replace(current_manifest, desired_manifest)
Function to determine if a resource requires a replace operation instead of apply. This can occur due to list merging, or updating envVars
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current_manifest
|
dict
|
The current manifest in the cluster |
required |
desired_manifest
|
dict
|
The desired manifest that should be applied |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
If the current manifest requires a replace operation |
Source code in oper8/deploy_manager/replace_utils.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
exceptions
This module implements custom exceptions
ClusterError
Bases: Oper8FatalError
Exception caused during chart construction when a cluster operation fails in an unexpected way.
Source code in oper8/exceptions.py
50 51 52 53 |
|
ConfigError
Bases: Oper8FatalError
Exception caused during usage of user-provided configuration
Source code in oper8/exceptions.py
46 47 |
|
Oper8DeprecationWarning
Bases: DeprecationWarning
This warning is issued for deprecated APIs
Source code in oper8/exceptions.py
120 121 |
|
Oper8Error
Bases: Exception
Base class for all oper8 exceptions
Source code in oper8/exceptions.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
is_fatal_error
property
Property indicating whether or not this error should signal a fatal state in the rollout
__init__(message, is_fatal_error)
Construct with a flag indicating whether this is a fatal error. This will be a static property of all children.
Source code in oper8/exceptions.py
11 12 13 14 15 16 |
|
Oper8ExpectedError
Bases: Oper8Error
An Oper8ExpectedError is one that indicates an expected failure condition that should cause a reconciliation to terminate, but is expected to resolve in a subsequent reconciliation.
Source code in oper8/exceptions.py
59 60 61 62 63 64 65 66 |
|
Oper8FatalError
Bases: Oper8Error
An Oper8FatalError is one that indicates an unexpected, and likely unrecoverable, failure during a reconciliation.
Source code in oper8/exceptions.py
29 30 31 32 33 34 35 |
|
Oper8PendingDeprecationWarning
Bases: PendingDeprecationWarning
This warning is issued for APIs that are still supported but will be removed eventually
Source code in oper8/exceptions.py
124 125 |
|
PreconditionError
Bases: Oper8ExpectedError
Exception caused during chart construction when an expected precondition is not met.
Source code in oper8/exceptions.py
69 70 71 72 |
|
RolloutError
Bases: Oper8FatalError
Exception indicating a failure during application rollout
Source code in oper8/exceptions.py
38 39 40 41 42 43 |
|
VerificationError
Bases: Oper8ExpectedError
Exception caused during resource verification when a desired verification state is not reached.
Source code in oper8/exceptions.py
75 76 77 78 |
|
assert_cluster(condition, message='')
Replacement for assert() which will throw a ClusterError. This should be used when building a chart which requires that an operation in the cluster (such as fetching an existing secret) succeeds.
Source code in oper8/exceptions.py
110 111 112 113 114 115 116 |
|
assert_config(condition, message='')
Replacement for assert() which will throw a ConfigError. This should be used when building a chart which requires that certain conditions be true in the deploy_config or app_config.
Source code in oper8/exceptions.py
101 102 103 104 105 106 107 |
|
assert_precondition(condition, message='')
Replacement for assert() which will throw a PreconditionError. This should be used when building a chart which requires that a precondition is met before continuing.
Source code in oper8/exceptions.py
84 85 86 87 88 89 90 |
|
assert_verified(condition, message='')
Replacement for assert() which will throw a VerificationError. This should be used when verifying the state of a resource in the cluster.
Source code in oper8/exceptions.py
93 94 95 96 97 98 |
|
log_format
Custom logging formats that contain more detailed oper8 logs
Oper8JsonFormatter
Bases: AlogJsonFormatter
Custom Log Format that extends AlogJsonFormatter to add multiple oper8 specific fields to the json. This includes things like identifiers of the resource being reconciled, reconciliationId, and thread information
Source code in oper8/log_format.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
managed_object
Helper object to represent a kubernetes object that is managed by the operator
ManagedObject
Basic struct to represent a managed kubernetes object
Source code in oper8/managed_object.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
__hash__()
Hash explicitly excludes the definition so that the object's identifier in a map can be based only on the unique identifier of the resource in the cluster. If the original resource did not provide a unique identifier then use the apiVersion, kind, and name
Source code in oper8/managed_object.py
48 49 50 51 52 53 54 |
|
get(*args, **kwargs)
Pass get calls to the objects definition
Source code in oper8/managed_object.py
38 39 40 |
|
patch
This module holds shared semantics for patching resources using temporary_patch
apply_patches(internal_name, resource_definition, temporary_patches)
Apply all temporary patches to the given resource from the given list. The patches are applied in-place.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
internal_name
|
str
|
str The name given to the internal node of the object. This is used to identify which patches apply to this object. |
required |
resource_definition
|
dict
|
dict The dict representation of the object to patch |
required |
temporary_patches
|
List[dict]
|
List[dict] The list of temporary patches that apply to this rollout |
required |
Returns:
Name | Type | Description |
---|---|---|
patched_definition |
dict The dict representation of the object with patches applied |
Source code in oper8/patch.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
patch_strategic_merge
This module implements Patch Strategic Merge following the semantics in:
- kustomize: https://kubectl.docs.kubernetes.io/references/kustomize/glossary/#patchstrategicmerge
- kubernetes: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-api-machinery/strategic-merge-patch.md
patch_strategic_merge(resource_definition, patch, merge_patch_keys=None)
Apply a Strategic Merge Patch based on JSON Merge Patch (rfc 7386)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource_definition
|
dict
|
dict The dict representation of the kubernetes resource |
required |
patch
|
dict
|
dict The formatted patch to apply |
required |
merge_patch_keys
|
Dict[str, str]
|
Dict[str, str] The mapping from paths to merge keys used to perform merge semantics for list elements |
None
|
Returns:
Name | Type | Description |
---|---|---|
patched_resource_definition |
dict
|
dict The patched version of the resource_definition |
Source code in oper8/patch_strategic_merge.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
reconcile
The ReconcileManager class manages an individual reconcile of a controller. This setups up the session, constructs the controller, and runs its reconcile
ReconcileManager
This class manages reconciliations for an instance of Oper8. It's primary function is to run reconciles given a CR manifest, Controller, and the current cluster state via a DeployManager.
Source code in oper8/reconcile.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 |
|
__init__(home_dir=None, deploy_manager=None, enable_vcs=None, reimport_controller=True)
The constructor sets up the properties used across every reconcile and checks that the current config is valid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
home_dir
|
str
|
Optional[str]=None The root directory for importing controllers or VCS checkout |
None
|
deploy_manager
|
Optional[DeployManagerBase]
|
Optional[DeployManager]=None Deploy manager to use. If not given, a new DeployManager will be created for each reconcile. |
None
|
enable_vcs
|
Optional[bool]
|
Optional[bool]=True Parameter to manually control the state of VCS on a per instance basis |
None
|
reimport_controller
|
Optional[bool]
|
Optional[bool]=None Parameter to manually control if a controller needs to be reimported each reconcile. |
True
|
Source code in oper8/reconcile.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
|
configure_logging(cr_manifest, reconciliation_id)
classmethod
Configure the logging for a given reconcile
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cr_manifest
|
Config
|
aconfig.Config The resource to get annotation overrides from |
required |
reconciliation_id
|
str
|
str The unique id for the reconciliation |
required |
Source code in oper8/reconcile.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
|
generate_id()
classmethod
Generates a unique human readable id for this reconciliation
Returns:
Name | Type | Description |
---|---|---|
id |
str
|
str A unique base32 encoded id |
Source code in oper8/reconcile.py
385 386 387 388 389 390 391 392 393 394 395 396 397 |
|
parse_manifest(resource)
classmethod
Parse a raw resource into an aconfig Config
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource
|
Union[dict, Config]
|
Union[dict, aconfig.Config]) The resource to be parsed into a manifest |
required |
Returns cr_manifest: aconfig.Config The parsed and validated config
Source code in oper8/reconcile.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
|
reconcile(controller_info, resource, is_finalizer=False)
This is the main entrypoint for reconciliations and contains the core implementation. The general reconcile path is as follows:
1. Parse the raw CR manifest
2. Setup logging based on config with overrides from CR
3. Check if the CR is paused and for strict versioning
4. Setup directory if VCS is enabled
5. Import and construct the Controller
6. Setup the DeployManager and Session objects
7. Run the Controller reconcile
Parameters:
Name | Type | Description | Default |
---|---|---|---|
controller_info
|
CONTROLLER_INFO
|
CONTROLLER_INFO The description of a controller. See CONTROLLER_INFO for more information |
required |
resource
|
Union[dict, Config]
|
Union[dict, aconfig.Config] A raw representation of the resource to be reconciled |
required |
is_finalizer
|
bool
|
bool=False Whether the resource is being deleted |
False
|
Returns:
Name | Type | Description |
---|---|---|
reconcile_result |
ReconciliationResult
|
ReconciliationResult The result of the reconcile |
Source code in oper8/reconcile.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
run_controller(controller, session, is_finalizer)
Run the Controller's reconciliation or finalizer with the constructed Session. This function also updates the CR status and handles requeue logic.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
controller
|
CONTROLLER_TYPE
|
Controller The Controller being reconciled |
required |
session
|
Session
|
Session The current Session state |
required |
is_finalizer
|
bool
|
Whether the resource is being deleted |
required |
Returns:
Name | Type | Description |
---|---|---|
reconciliation_result |
ReconciliationResult
|
ReconciliationResult The result of the reconcile |
Source code in oper8/reconcile.py
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 |
|
safe_reconcile(controller_info, resource, is_finalizer=False)
This function calls out to reconcile but catches any errors thrown. This function guarantees a safe result which is needed by some Watch Managers
Parameters:
Name | Type | Description | Default |
---|---|---|---|
controller_info
|
CONTROLLER_INFO
|
CONTROLLER_INFO The description of a controller. See CONTROLLER_INFO for more information |
required |
resource
|
dict
|
Union[dict, aconfig.Config] A raw representation of the reconcile |
required |
is_finalize
|
bool=False Whether the resource is being deleted |
required |
Returns:
Name | Type | Description |
---|---|---|
reconcile_result |
ReconciliationResult
|
ReconciliationResult The result of the reconcile |
Source code in oper8/reconcile.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
|
setup_controller(controller_info)
Import the requested Controller class and enable any compatibility layers
Parameters:
Name | Type | Description | Default |
---|---|---|---|
controller_info
|
CONTROLLER_INFO
|
CONTROLLER_INFO The description of a controller. See CONTROLLER_INFO for more information |
required |
Returns: controller: The required Controller Class
Source code in oper8/reconcile.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
|
setup_deploy_manager(cr_manifest)
Configure a deploy_manager for a reconcile given a manifest
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cr_manifest
|
Config
|
aconfig.Config The resource to be used as an owner_ref |
required |
Returns:
Name | Type | Description |
---|---|---|
deploy_manager |
DeployManagerBase
|
DeployManagerBase The deploy_manager to be used during reconcile |
Source code in oper8/reconcile.py
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
|
setup_session(controller, cr_manifest, deploy_manager, reconciliation_id)
Construct the session, including gathering the backend config and any temp patches
Parameters:
Name | Type | Description | Default |
---|---|---|---|
controller
|
CONTROLLER_TYPE
|
Controller The controller class being reconciled |
required |
cr_manifest
|
Config
|
aconfig.Config The resource being reconciled |
required |
deploy_manager
|
DeployManagerBase
|
DeployManagerBase The deploy manager used in the cluster |
required |
reconciliation_id
|
str
|
str The id for the reconcile |
required |
Return
session: Session The session for reconcile
Source code in oper8/reconcile.py
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 |
|
setup_vcs(cr_manifest)
Setups the VCS directory and sys.path for a reconcile. This function also ensures that the version is valid if config.strict_versioning is enabled.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cr_manifest
|
Config
|
aconfig.Config The cr manifest to pull the requested version from. |
required |
Source code in oper8/reconcile.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
|
ReconciliationResult
dataclass
ReconciliationResult is the result of a reconciliation session
Source code in oper8/reconcile.py
69 70 71 72 73 74 75 76 77 78 |
|
RequeueParams
dataclass
RequeueParams holds parameters for requeue request
Source code in oper8/reconcile.py
58 59 60 61 62 63 64 65 66 |
|
rollout_manager
This module holds the implementation of the DAG constructs used to perform the dependency management for rollout
RolloutManager
This class manages the dependencies needed to roll out a set of nodes
Source code in oper8/rollout_manager.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
|
__init__(session, after_deploy=None, after_deploy_unsuccessful=None, after_verify=None, after_verify_unsuccessful=None)
Construct with the fully-populated session for the rollout
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The current session for the reconciliation |
required |
after_deploy
|
Optional[Callable[[Session], bool]]
|
Optional[Callable[[Session] bool]] An optional callback hook that will be invoked after the deploy phase completes. The return indicates whether the validation has passed. |
None
|
after_deploy_unsuccessful
|
Optional[Callable[[Session], bool]]
|
Optional[Callable[[Session] bool]] An optional callback hook that will be invoked after the deploy phase ends with incomplete or failed status. The return indicates whether the validation has passed. |
None
|
after_verify
|
Optional[Callable[[Session], bool]]
|
Optional[Callable[[Session] None]] An optional callback hook that will be invoked after the verify phase completes. The return indicates whether the validation has passed. |
None
|
after_verify_unsuccessful
|
Optional[Callable[[Session], bool]]
|
Optional[Callable[[Session] None]] An optional callback hook that will be invoked after the verify phase ends with failure. The return indicates whether the validation has passed. |
None
|
Source code in oper8/rollout_manager.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
rollout()
Perform the rollout
The logic has four phases
- Deploy Graph: This phase executes the Runner which runs the deploy() function for each Component in dependency order. For graph edges with configured verification functions, they are also executed during this phase.
- After Deploy: If configured with an after_deploy hook and (1) completed all nodes successfully, this function is called. Any raised exceptions indicate that the rollout should not proceed.
- Verify Graph: This phase executes the Runner which runs the verify() function for each Component in dependency order.
- After Verify: If configured with an after_verify hook and (3) completed all nodes successfully, this function is called. Any raised exceptions indicate that the rollout is not fully verified.
The rollout can terminate in one of three states
- incomplete AND failed: Something unexpected happened and the rollout terminated in a fatal state.
- incomplete AND NOT failed: One or more nodes did not pass their verify steps, but all deploy steps that were attempted succeeded.
- complete AND NOT failed: The rollout completed all nodes, including all verify steps. The managed components are ready to take traffic.
Returns:
Name | Type | Description |
---|---|---|
completion_state |
CompletionState
|
CompletionState The final completion state of all nodes in the rollout Runner. This is a logical composition of the outputs of the above phases based on the termination logic above. |
Source code in oper8/rollout_manager.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 |
|
run_node(func, session, component, fail_halt_runner=True)
classmethod
Generic function to execute a node during Rollout
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable[[Component, Session], bool]
|
Callable[[Component,Session], bool] The function to be called |
required |
session
|
Session
|
Session The session that's currently being rolled out |
required |
component
|
Component
|
Component The component being rolled out |
required |
Source code in oper8/rollout_manager.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
deploy_component(session, component)
Deploy a component given a particular session
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The current rollout session |
required |
component
|
Component
|
Component The component to deploy |
required |
Returns:
Name | Type | Description |
---|---|---|
result |
bool
|
bool The result of the deploy |
Source code in oper8/rollout_manager.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
disable_component(session, component)
Disable a component given a particular session
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The current rollout session |
required |
component
|
Component
|
Component The component to disable |
required |
Returns:
Name | Type | Description |
---|---|---|
result |
bool
|
bool The result of the disable |
Source code in oper8/rollout_manager.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
verify_component(session, component)
Verify a component given a particular session
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The current rollout session |
required |
component
|
Component
|
Component The component to verify |
required |
Returns:
Name | Type | Description |
---|---|---|
result |
bool
|
bool The result of the verify |
Source code in oper8/rollout_manager.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
session
This module holds the core session state for an individual reconciliation
Session
A session is the core context manager for the state of an in-progress reconciliation
Source code in oper8/session.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 |
|
api_version
property
The api version of the operand for this CR
config
property
The backend config for this reconciliation
cr_manifest
property
The full CR manifest that triggered this reconciliation
current_version
property
The most recently reconciled version of the operand
deploy_manager
property
Allow read access to the deploy manager
finalizers
property
The metadata.namespace for this CR
graph
property
The component graph
id
property
The unique reconciliation ID
kind
property
The kind of the operand for this CR
metadata
property
The metadata for this CR
name
property
The metadata.name for this CR
namespace
property
The metadata.namespace for this CR
spec
property
The spec section of the CR manifest
status
property
The operand status
temporary_patches
property
Ordered list of temporary patches that apply to the operand being reconciled
version
property
The spec.version for this CR
__init__(reconciliation_id, cr_manifest, config, deploy_manager, temporary_patches=None)
Construct a session object to hold the state for a reconciliation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reconciliation_id
|
str
|
str The unique ID for this reconciliation |
required |
cr_manifest
|
Config
|
aconfig.Config The full value of the CR manifest that triggered this reconciliation |
required |
config
|
Config
|
aconfig.Config The compiled backend config for this reconciliation |
required |
deploy_manager
|
DeployManagerBase
|
DeployManagerBase The preconfigured DeployManager in charge of running the actual deploy operations for this deployment |
required |
temporary_patches
|
Optional[List[dict]]
|
list(dict) List of temporary patch object to apply to resources managed by this rollout |
None
|
Source code in oper8/session.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
add_component(component)
Add a component to this deploy associated with a specific application
Parameters:
Name | Type | Description | Default |
---|---|---|---|
component
|
COMPONENT_INSTANCE_TYPE
|
Component The component to add to this deploy |
required |
disabled
|
bool Whether or not the component is disabled in this deploy |
required |
Source code in oper8/session.py
219 220 221 222 223 224 225 226 227 228 229 |
|
add_component_dependency(component, upstream_component, verify_function=None)
Add a dependency indicating that one component requires an upstream component to be deployed before it can be deployed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
component
|
Union[str, COMPONENT_INSTANCE_TYPE]
|
str or Component The component or name of component in the deploy that must wait for the upstream |
required |
upstream_component
|
Union[str, COMPONENT_INSTANCE_TYPE]
|
str or Component The upstream component or name of upstream that must be deployed before component |
required |
verify_function
|
Optional[COMPONENT_VERIFY_FUNCTION]
|
callable
A callable function of the form |
None
|
Source code in oper8/session.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
|
filter_objects_current_state(kind, api_version=None, label_selector=None, field_selector=None, namespace=_SESSION_NAMESPACE)
Get the current state of the given object in the namespace of this session
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kind
|
str
|
str The kind of the object to fetch |
required |
label_selector
|
Optional[str]
|
str The label selector to filter the results by |
None
|
field_selector
|
Optional[str]
|
str The field selector to filter the results by |
None
|
api_version
|
Optional[str]
|
str The api_version of the resource kind to fetch |
None
|
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool Whether or not the state fetch operation succeeded |
current_state |
List[dict]
|
List[Dict] The list of resources in dict representation, or [] if none match |
Source code in oper8/session.py
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
|
get_component(name, disabled=None)
Get an individual component by name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
str Name of component to return |
required |
disabled
|
Optional[bool]
|
Optional[bool] Option on wether to return disabled components. If this option is not supplied then the referenced component will be returned irregardless whether its disabled or enabled |
None
|
Returns:
Name | Type | Description |
---|---|---|
component |
Optional[COMPONENT_INSTANCE_TYPE]
|
Optional[Component] The component with the given name or None if component does not exit or does not match disabled arg |
Source code in oper8/session.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
|
get_component_dependencies(component)
Get the list of (upstream_name, verify_function) tuples for a given component.
This is primarily for use inside of the RolloutManager. Do not use
this method in user code unless you know what you're doing!
Parameters:
Name | Type | Description | Default |
---|---|---|---|
component_name
|
str The name of the component to lookup dependencies for |
required |
Returns:
Name | Type | Description |
---|---|---|
upstreams |
List[Tuple[COMPONENT_INSTANCE_TYPE, Optional[COMPONENT_VERIFY_FUNCTION]]]
|
List[Tuple[str, Optional[VERIFY_FUNCTION]]] The list of upstream (name, verify_fn) pairs |
Source code in oper8/session.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
|
get_components(disabled=False)
Get all components associated with an application
Parameters:
Name | Type | Description | Default |
---|---|---|---|
disabled
|
bool
|
bool Whether to return disabled or enabled components |
False
|
Returns:
Name | Type | Description |
---|---|---|
components |
List[COMPONENT_INSTANCE_TYPE]
|
list(Component) The list of Component objects associated with the given application |
Source code in oper8/session.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
|
get_object_current_state(kind, name, api_version=None, namespace=_SESSION_NAMESPACE)
Get the current state of the given object in the namespace of this session
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kind
|
str
|
str The kind of the object to fetch |
required |
name
|
str
|
str The full name of the object to fetch |
required |
api_version
|
Optional[str]
|
str The api_version of the resource kind to fetch |
None
|
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool Whether or not the state fetch operation succeeded |
current_state |
Optional[dict]
|
dict or None The dict representation of the current object's configuration, or None if not present |
Source code in oper8/session.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 |
|
get_scoped_name(name)
Get a name that is scoped to the application instance
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
str The name of a resource that will be managed by this operator which should have instance name scoping applied |
required |
Returns:
Name | Type | Description |
---|---|---|
scoped_name |
str
|
str The scoped and truncated version of the input name |
Source code in oper8/session.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
|
get_status()
Get the status of the resource being managed by this session or an empty dict if not available
Returns:
Name | Type | Description |
---|---|---|
current_status |
dict
|
dict The dict representation of the status subresource for the CR being managed by this session |
Source code in oper8/session.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 |
|
get_truncated_name(name)
staticmethod
Perform truncation on a cluster name to make it conform to kubernetes limits while remaining unique.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
str The name of the resource that should be truncated and made unique |
required |
Returns:
Name | Type | Description |
---|---|---|
truncated_name |
str
|
str A version of name that has been truncated and made unique |
Source code in oper8/session.py
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
|
setup_vcs
This module uses VCS to create a trimmed down repo with a selection of local branches and tags and a fully flattened history.
VCSRepoInitializer
This class encapsulates the key attributes of the VCS repo initialization process
Source code in oper8/setup_vcs.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 |
|
__init__(source, destination, force)
Initialize and set up the repos and common attributes
Source code in oper8/setup_vcs.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
clean_up()
Clean out all unnecessary content from the destination repo
Source code in oper8/setup_vcs.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
|
initialize_branches(branch_expr, tag_expr)
Perform the initialize of all branches in the destination repo from the branches and tags that match the given expressions.
Source code in oper8/setup_vcs.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
setup_vcs(source, destination=None, branch_expr=None, tag_expr=__UNSET__, force=False)
This utility will initialize an operator's VCS directory for use with oper8's VCS versioning.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
str
|
The path to the source repository on disk |
required |
destination
|
Optional[str]
|
The path where the VCS repo should be created |
None
|
branch_expr
|
Optional[List[str]]
|
Regular expression(s) to use to identify branches to retain in the VCS repo |
None
|
tag_expr
|
Optional[List[str]]
|
Regular expression(s) to use to identify tags to retain in the VCS repo |
__UNSET__
|
force
|
bool
|
Force overwrite existing destination |
False
|
Source code in oper8/setup_vcs.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
status
This module holds the common functionality used to represent the status of resources managed by oper8
Oper8 supports the following orthogonal status conditions:
- Ready: True if the service is able to take traffic
- Updating: True if a modification is being actively applied to the application
Additionally, oper8 supports a top-level status element to report the detailed status of the managed components. The schema is: { "componentStatus": { "allComponents": [list of all node names], "deployedComponents": [list of nodes that have successfully deployed], "verifiedComponents": [list of nodes that have successfully verified], "failedComponents": [list of nodes that have successfully verified], "deployed": "N/M", "verified": "N/M", } }
ReadyReason
Bases: Enum
Nested class to hold reason constants for the Ready condition
Source code in oper8/status.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
ServiceStatus
Bases: Enum
Nested class to hold status constants for the service status
Source code in oper8/status.py
112 113 114 115 116 117 118 119 120 121 122 |
|
UpdatingReason
Bases: Enum
Nested class to hold reason constants for the Updating condition
Source code in oper8/status.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
get_condition(type_name, current_status)
Extract the given condition type from a status object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type
|
str The condition type to fetch |
required | |
current_status
|
dict
|
dict The dict representation of the status for a given application |
required |
Returns:
Name | Type | Description |
---|---|---|
condition |
dict
|
dict The condition object if found, empty dict otherwise |
Source code in oper8/status.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
|
get_version(current_status)
Extract the current version (not desired version) from a status object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current_status
|
dict
|
dict The dict representation of the status for a given application |
required |
Returns:
Name | Type | Description |
---|---|---|
version |
Optional[str]
|
Optional[dict] The current version if found in a status object, None otherwise. |
Source code in oper8/status.py
415 416 417 418 419 420 421 422 423 424 425 426 427 |
|
make_application_status(ready_reason=None, ready_message='', updating_reason=None, updating_message='', component_state=None, external_conditions=None, external_status=None, version=None, supported_versions=None, operator_version=None, kind=None)
Create a full status object for an application
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ready_reason
|
Optional[Union[ReadyReason, str]]
|
Optional[ReadyReason or str] The reason enum for the Ready condition |
None
|
ready_message
|
str
|
str Plain-text message explaining the Ready condition value |
''
|
updating_reason
|
Optional[Union[UpdatingReason, str]]
|
Optional[UpdatingReason or str] The reason enum for the Updating condition |
None
|
updating_message
|
str
|
str Plain-text message explaining the Updating condition value |
''
|
component_state
|
Optional[CompletionState]
|
Optional[CompletionState] The terminal state of components in the latest rollout |
None
|
external_conditions
|
Optional[List[dict]]
|
Optional[List[dict]] Additional conditions to include in the update |
None
|
external_status
|
Optional[dict]
|
Optional[dict] Additional key/value status elements besides "conditions" that should be preserved through the update |
None
|
version
|
Optional[str]
|
Optional[str] The verified version of the application |
None
|
supported_versions
|
Optional[List[str]]
|
Optional[List[str]] The list of supported versions for this application |
None
|
operator_version
|
Optional[str]
|
Optional[str] The operator version for this application |
None
|
kind
|
Optional[str]
|
Optional[str] The kind of reconciling CR. If specified, this function adds service status field which is compliant with IBM Cloud Pak requirements. |
None
|
Returns:
Name | Type | Description |
---|---|---|
current_status |
dict
|
dict Dict representation of the status for the application |
Source code in oper8/status.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
status_changed(current_status, new_status)
Compare two status objects to determine if there is a meaningful change between the current status and the proposed new status. A meaningful change is defined as any change besides a timestamp.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current_status
|
dict
|
dict The raw status dict from the current CR |
required |
new_status
|
dict
|
dict The proposed new status |
required |
Returns:
Name | Type | Description |
---|---|---|
status_changed |
bool
|
bool True if there is a meaningful change between the current status and the new status |
Source code in oper8/status.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
|
update_application_status(current_status, **kwargs)
Create an updated status based on the values in the current status
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current_status
|
dict
|
dict The dict representation of the status for a given application |
required |
**kwargs
|
Additional keyword args to pass to make_application_status |
{}
|
Returns:
Name | Type | Description |
---|---|---|
updated_status |
dict
|
dict Updated dict representation of the status for the application |
Source code in oper8/status.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
update_resource_status(deploy_manager, kind, api_version, name, namespace, **kwargs)
Create an updated status based on the values in the current status
Parameters:
Name | Type | Description | Default |
---|---|---|---|
deploy_manager
|
DeployManagerBase
|
DeployManagerBase The deploymanager used to get and set status |
required |
kind
|
str
|
str The kind of the resource |
required |
api_version
|
str
|
str The api_version of the resource |
required |
name
|
str
|
str The name of the resource |
required |
namespace
|
str
|
str The namespace the resource is located in |
required |
**kwargs
|
dict
|
Dict Any additional keyword arguments to be passed to update_application_status |
{}
|
Returns:
Name | Type | Description |
---|---|---|
status_object |
dict
|
Dict The applied status if successful |
Source code in oper8/status.py
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
|
test_helpers
helpers
This module holds common helper functions for making testing easy
DummyComponentBase
Bases: Component
This base class provides all of the common functionality for DummyComponent and DummyLegacyComponent
Source code in oper8/test_helpers/helpers.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
|
DummyController
Bases: Controller
Configurable implementation of a controller that can be used in unit tests to simulate Controller behavior
Source code in oper8/test_helpers/helpers.py
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 |
|
setup_components(session)
Set up the components based on the component specs passed in
Source code in oper8/test_helpers/helpers.py
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 |
|
DummyNodeComponent
Bases: DummyComponentBase
Configurable dummy component which will create an arbitrary set of resource node instances.
Source code in oper8/test_helpers/helpers.py
461 462 463 464 465 466 467 468 469 470 |
|
__init__(session, *args, **kwargs)
Construct with the additional option to fail build_chart
Source code in oper8/test_helpers/helpers.py
467 468 469 470 |
|
FailOnce
Helper callable that will fail once on the N'th call
Source code in oper8/test_helpers/helpers.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
|
MockComponent
Bases: DummyNodeComponent
Dummy component with a valid mock name
Source code in oper8/test_helpers/helpers.py
473 474 475 476 |
|
MockDeployManager
Bases: DryRunDeployManager
The MockDeployManager wraps a standard DryRunDeployManager and adds configuration options to simulate failures in each of its operations.
Source code in oper8/test_helpers/helpers.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
__init__(deploy_fail=False, deploy_raise=False, disable_fail=False, disable_raise=False, get_state_fail=False, get_state_raise=False, watch_fail=False, watch_raise=False, generate_resource_version=True, set_status_fail=False, set_status_raise=False, auto_enable=True, resources=None, resource_dir=None, **kwargs)
This DeployManager can be configured to have various failure cases and will mock the state of the cluster so that get_object_current_state will pull its information from the local dict.
Source code in oper8/test_helpers/helpers.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
enable_mocks()
Turn the mocks on
Source code in oper8/test_helpers/helpers.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
MockTopApp
Bases: Controller
Mock implementation of a top-level Controller to allow subsystems to be tested as "children"
Source code in oper8/test_helpers/helpers.py
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 |
|
MockedOpenshiftDeployManager
Bases: OpenshiftDeployManager
Override class that uses the mocked client
Source code in oper8/test_helpers/helpers.py
448 449 450 451 452 453 454 455 456 457 458 |
|
ModuleExit
Bases: Exception
Exception we'll use to break out when sys.exit was called
Source code in oper8/test_helpers/helpers.py
643 644 |
|
deep_merge(a, b)
NOTE: This should really be eliminated in favor of just using merge_configs
Source code in oper8/test_helpers/helpers.py
823 824 825 826 827 |
|
default_branch_name()
cached
Helper to get the current git context's default branch name
Source code in oper8/test_helpers/helpers.py
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 |
|
library_config(**config_overrides)
This context manager sets library config values temporarily and reverts them on completion
Source code in oper8/test_helpers/helpers.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
make_patch(patch_type, body, name='test', target=None, namespace=TEST_NAMESPACE, api_version='org.oper8/v1', kind='TemporaryPatch')
Make a sample TemporaryPatch resource body
Source code in oper8/test_helpers/helpers.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
|
mock_config_file(config_object)
Yuck! Ansible makes it tough to actually inject parameters in since it expects that modules will only be run by its parent runner.
Source code in oper8/test_helpers/helpers.py
675 676 677 678 679 680 681 682 683 684 685 |
|
setup_session_ctx(*args, **kwargs)
Context manager wrapper around setup_session. This simplifies the porting process from WA and really provides no functional benefit.
Source code in oper8/test_helpers/helpers.py
116 117 118 119 120 121 |
|
kub_mock
This module implements a mock of the kubernetes client library which can be used to patch the api client in an ansible module.
We attempt to emulate the internals of the kubernetes api_client, but this is based on code inspection of the current implementation and is certainly subject to change!
MockKubClient
Bases: ApiClient
Mocked version of kubernetes.client.ApiClient which swaps out the implementation of call_api() to use preconfigured responses
Source code in oper8/test_helpers/kub_mock.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 |
|
call_api(resource_path, method, path_params=None, query_params=None, header_params=None, body=None, **kwargs)
Mocked out call function to return preconfigured responses
this is set up to work with how openshift.dynamic.DynamicClient
calls self.client.call_api. It (currently) passes some as positional args and some as kwargs.
Source code in oper8/test_helpers/kub_mock.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
|
MockWatchStreamResponse
Helper class used to stream resources from the MockKubeClient using a queue. When the streaming method is called the MockWatchStreamResponse registers a threading queue with the MockKubClient and yields all events
Source code in oper8/test_helpers/kub_mock.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
stream(*args, **kwargs)
Continuously yield events from the cluster until the shutdown or timeout
Source code in oper8/test_helpers/kub_mock.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
mock_kub_client_constructor(*args, **kwargs)
Context manager to patch the api client
Source code in oper8/test_helpers/kub_mock.py
957 958 959 960 961 962 963 964 965 966 967 |
|
oper8x_helpers
This module holds helpers that rely on oper8.x
set_tls_ca_secret(session)
Set the key/cert content for the shared CA secret. This function returns the pem-encoded values for convenience in other tests
Source code in oper8/test_helpers/oper8x_helpers.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
pwm_helpers
Utils and common classes for the python watch manager tests
DisabledLeadershipManager
Bases: LeadershipManagerBase
Leadership Manager that is always disabled
Source code in oper8/test_helpers/pwm_helpers.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
MockedReconcileThread
Bases: ReconcileThread
Subclass of ReconcileThread that mocks the subprocess. This was more reliable than using unittest.mock
Source code in oper8/test_helpers/pwm_helpers.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
|
mocked_create_and_start_entrypoint(logging_queue, request, result_pipe, wait_time=0.5, returned_messages=None)
Source code in oper8/test_helpers/pwm_helpers.py
211 212 213 214 215 216 217 218 219 220 221 |
|
read_heartbeat_file(hb_file)
Parse a heartbeat file into a datetime
Source code in oper8/test_helpers/pwm_helpers.py
224 225 226 227 228 229 |
|
utils
Common utilities shared across components in the library
abstractclassproperty
This decorator implements a classproperty that will raise when accessed
Source code in oper8/utils.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
|
classproperty
@classmethod+@property CITE: https://stackoverflow.com/a/22729414
Source code in oper8/utils.py
285 286 287 288 289 290 291 292 293 294 |
|
add_finalizer(session, finalizer)
This helper adds a finalizer to current session CR
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
SESSION_TYPE
|
Session The session for the current deploy |
required |
finalizer
|
str
|
str The finalizer to be added |
required |
Source code in oper8/utils.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
|
get_manifest_version(cr_manifest)
Get the version for a given custom resource or from the config if version override provided
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cr_manifest
|
Config
|
aconfig.Config The manifest to pull the version from |
required |
Returns:
Name | Type | Description |
---|---|---|
version |
str
|
str The current version |
Source code in oper8/utils.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
|
get_passthrough_annotations(session)
This helper gets the set of annotations that should be passed from a parent CR to a child subsystem CR.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
DeploySession The session for the current deploy |
required |
Returns:
Name | Type | Description |
---|---|---|
annotations |
Dict[str, str] The dict mapping of annotations that should be passed through |
Source code in oper8/utils.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
|
merge_configs(base, overrides)
Helper to perform a deep merge of the overrides into the base. The merge is done in place, but the resulting dict is also returned for convenience.
The merge logic is quite simple: If both the base and overrides have a key and the type of the key for both is a dict, recursively merge, otherwise set the base value to the override value.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base
|
dict The base config that will be updated with the overrides |
required | |
overrides
|
dict The override config |
required |
Returns:
Name | Type | Description |
---|---|---|
merged |
dict
|
dict The merged results of overrides merged onto base |
Source code in oper8/utils.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
nested_get(dct, key, dflt=None)
Helper to get values from a dict using 'foo.bar' key notation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dct
|
dict
|
dict The dict into which the key will be set |
required |
key
|
str
|
str Key that may contain '.' notation indicating dict nesting |
required |
Returns:
Name | Type | Description |
---|---|---|
val |
Any
|
Any Whatever is found at the given key or None if the key is not found. This includes missing intermediate dicts. |
Source code in oper8/utils.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|
nested_set(dct, key, val)
Helper to set values in a dict using 'foo.bar' key notation
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dct
|
dict
|
dict The dict into which the key will be set |
required |
key
|
str
|
str Key that may contain '.' notation indicating dict nesting |
required |
val
|
Any
|
Any The value to place at the nested key |
required |
Source code in oper8/utils.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
remove_finalizer(session, finalizer)
This helper gets removes a finalizer from the current session controller
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
SESSION_TYPE
|
Session The session for the current deploy |
required |
finalizer
|
str
|
str The finalizer to remove |
required |
Returns:
Name | Type | Description |
---|---|---|
annotations |
Dict[str, str] The dict mapping of annotations that should be passed through |
Source code in oper8/utils.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
sanitize_for_serialization(obj)
Builds a JSON POST object. If obj is None, return None. If obj is str, int, long, float, bool, return directly. If obj is datetime.datetime, datetime.date convert to string in iso8601 format. If obj is list, sanitize each element in the list. If obj is dict, return the dict. If obj is OpenAPI model, return the properties dict. :param obj: The data to serialize. :return: The serialized form of data.
Source code in oper8/utils.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
|
vcs
Version Control System class manages a specific git directory.
VCS
Generic class for handling a git repository. This class contains helper functions to get, list, and checkout references. Each instance of this class corresponds to a different git directory
Source code in oper8/vcs.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
|
head
property
Get a reference to the current HEAD
__init__(directory, create_if_needed=False, **kwargs)
Initialize the pygit2 Repository reference
Parameters:
Name | Type | Description | Default |
---|---|---|---|
directory
|
str
|
str The git directory |
required |
create_if_needed
|
bool
|
bool If True, the repo will be initialized if it doesn't already exist |
False
|
**kwargs
|
Passthrough args to the repository setup |
{}
|
Source code in oper8/vcs.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
|
add_remote(remote_name, remote_path)
Add a named remote to the repo
Parameters:
Name | Type | Description | Default |
---|---|---|---|
remote_name
|
str
|
str The name of the remote |
required |
remote_path
|
str
|
str The path on disk to the remote repo |
required |
Source code in oper8/vcs.py
250 251 252 253 254 255 256 257 258 259 |
|
checkout_detached_head(refish=None)
Check out the current HEAD commit as a detached head
Parameters:
Name | Type | Description | Default |
---|---|---|---|
refish
|
Optional[str]
|
Optional[str] The ref to check out. If not given, the current HEAD is used |
None
|
Source code in oper8/vcs.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
|
checkout_ref(refish, dest_path=None, method=VCSCheckoutMethod.WORKTREE, **kwargs)
Checkout a refish to a given destination directory. This function first attempts to create a worktree but on failure will do a traditional clone
Parameters:
Name | Type | Description | Default |
---|---|---|---|
refish
|
str
|
str The refish to be checked out in the dest_dir |
required |
dest_path
|
Optional[Path]
|
Optional[pathlib.Path] The destination directory if not in-place |
None
|
method
|
VCSCheckoutMethod
|
VCSCheckoutMethod=VCSCheckoutMethod.WORKTREE The checkout method to use, either a git clone or worktree add |
WORKTREE
|
Source code in oper8/vcs.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
|
compress_references()
Compress unreachable references in the repo
Source code in oper8/vcs.py
355 356 357 |
|
create_branch(branch_name, commit)
Create branch given a name and commit
Parameters:
Name | Type | Description | Default |
---|---|---|---|
branch_name
|
str
|
str The name to be created |
required |
commit
|
Commit
|
Commit The commit for the branch to be created from |
required |
Returns:
Name | Type | Description |
---|---|---|
branch |
Branch
|
Branch The created branch |
Source code in oper8/vcs.py
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
|
create_commit(message, parents=None, committer_name='Oper8', committer_email='noreply@oper8.org')
Create a commit in the repo with the files currently in the index
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str
|
str The commit message |
required |
parents
|
Optional[List[str]]
|
Optional[List[str]] Parent commit hashes |
None
|
committer_name
|
str
|
str The name of the committer |
'Oper8'
|
committer_email
|
str
|
str Email address for this committer |
'noreply@oper8.org'
|
Source code in oper8/vcs.py
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
delete_branch(branch_name)
Delete a branch from the repo
Parameters:
Name | Type | Description | Default |
---|---|---|---|
branch_name
|
str
|
str The name of the branch |
required |
Source code in oper8/vcs.py
321 322 323 324 325 326 327 328 |
|
delete_remote(remote_name)
Remove a remote from the repo
Parameters:
Name | Type | Description | Default |
---|---|---|---|
remote_name
|
str
|
str The name of the remote |
required |
Source code in oper8/vcs.py
261 262 263 264 265 266 267 268 |
|
delete_tag(tag_name)
Delete a tag from the repo
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tag_name
|
str
|
str The name of the tag |
required |
Source code in oper8/vcs.py
330 331 332 333 334 335 336 337 |
|
fetch_remote(remote_name, refs=None, wait=True)
Fetch content from the named remote. If no refs given, all refs are fetched.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
remote_name
|
str
|
str The name of the remote to fetch |
required |
refs
|
Optional[Set[str]]
|
Optional[Set[str]] The refs to fetch (fetch all if not given) |
None
|
wait
|
bool
|
bool If true, wait for fetch to complete |
True
|
Source code in oper8/vcs.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
|
get_ref(refish)
Get a git commit and reference from a shorthand string
Parameters:
Name | Type | Description | Default |
---|---|---|---|
refish
|
str
|
str The human readable form of a git reference like branch name or commit hash |
required |
Returns commit_and_reference: Tuple[Commit,Reference] Both a commit and reference for a given refish
Source code in oper8/vcs.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
list_refs()
List all of the tags and references in the repo
Returns ref_list: Set[str] A set of all references' shorthand as strings
Source code in oper8/vcs.py
137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
VCSCheckoutMethod
Bases: Enum
Enum for available VCS checkout methods
Source code in oper8/vcs.py
40 41 42 43 44 |
|
VCSConfigError
Bases: ConfigError
Error for VCS Specific config exception
Source code in oper8/vcs.py
55 56 |
|
VCSMultiProcessError
Bases: PreconditionError
VCS Error for when multiple git processes attempt to update the git directory at the same time
Source code in oper8/vcs.py
50 51 52 |
|
VCSRuntimeError
Bases: Oper8FatalError
Error for general git exceptions
Source code in oper8/vcs.py
59 60 |
|
verify_resources
This library holds common verification routines for individual kubernetes resources.
verify_deployment(object_state)
Verify that all members of a deployment are ready and all members are rolled out to new version in case of update.
Source code in oper8/verify_resources.py
151 152 153 154 155 156 157 158 159 160 161 162 |
|
verify_job(object_state)
Verify that a job has completed successfully
Source code in oper8/verify_resources.py
145 146 147 148 |
|
verify_pod(object_state)
Verify that a pod resources is ready
Source code in oper8/verify_resources.py
140 141 142 |
|
verify_resource(kind, name, api_version, session, *, namespace=_SESSION_NAMESPACE, verify_function=None, is_subsystem=False, condition_type=None, timestamp_key=None)
Verify a resource detailed in a ManagedObject.
we can't do type-hinting on the session because importing
DeploySession creates a circular dependency with Component. We should probably fix that...
This function will run the appropriate verification function for the given resource kind.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kind
|
str
|
str The kind of the resource to look for |
required |
name
|
str
|
str The name of the resource to look for |
required |
api_version
|
str
|
str The api_version of the resource to look for |
required |
session
|
DeploySession The current deployment session |
required |
Kwargs
is_subsystem: bool Whether or not the given kind is an oper8 subsystem condition_type: str For non-standard types, this is the type name for the condition to check for verification timestamp_key: str For non-standard types, this is the key in the condition to use to sort by date
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool True on successful deployment verification, False on failure conditions |
Source code in oper8/verify_resources.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
verify_statefulset(object_state)
Verify that all desired replicas of a StatefulSet are ready
Source code in oper8/verify_resources.py
165 166 167 168 169 170 171 172 173 |
|
verify_subsystem(object_state, desired_version=None)
Verify that an oper8-managed subsystem is ready
Source code in oper8/verify_resources.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
watch_manager
Top-level watch_manager imports
ansible_watch_manager
This module holds the ansible implementation of the WatchManager
ansible_watch_manager
Ansible-based implementation of the WatchManager
AnsibleWatchManager
Bases: WatchManagerBase
The AnsibleWatchManager uses the core of an ansible-based operator to manage watching resources. The key elements are:
- Manage a
watches.yaml
file for all watched resources - Manage a playbook for each watched resource
- Manage the ansible operator's executable as a subprocess
Source code in oper8/watch_manager/ansible_watch_manager/ansible_watch_manager.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
|
__init__(controller_type, *, ansible_base_path=None, ansible_entrypoint=None, ansible_args=None, manage_status=None, watch_dependent_resources=None, reconcile_period=None, playbook_parameters=None)
Construct with the core watch binding and configuration args for the watches.yaml and playbook.yaml files.
All args may be overridden in the ansible_watch_manager
section
of the library config. The precedence order is:
- Directly passed arguments
- Config values
- Default values from code
A passed None value in any of these is considered "unset"
Parameters:
Name | Type | Description | Default |
---|---|---|---|
controller_type
|
Type[Controller]
|
Type[Controller], The Controller type that will manage this group/version/kind |
required |
Kwargs
ansible_base_path: str
The base path where the ansible runtime will be run. This is
also used to determine where the watches.yaml and playbooks will
be managed.
ansible_entrypoint: str
The command to use to run ansible
ansible_args: str
Additional flags to be passed to ansible_entrypoint
manage_status: bool
Whether or not to let ansible manage status on the CR
watch_dependent_resources: bool
Whether or not to trigger a reconciliation on change to
dependent resources.
reconcile_period: str
String representation of the time duration to use for periodic
reconciliations
playbook_parameters: dict
Parameters to use to configure the k8s_application module in the
playbook
Source code in oper8/watch_manager/ansible_watch_manager/ansible_watch_manager.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
stop()
Attempt to terminate the ansible process. This asserts that the process has been created in order to avoid race conditions with a None check.
Source code in oper8/watch_manager/ansible_watch_manager/ansible_watch_manager.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
|
wait()
Wait for the ansible process to terminate
Source code in oper8/watch_manager/ansible_watch_manager/ansible_watch_manager.py
176 177 178 179 |
|
watch()
Start the global ansible process if not already started
This is intentionally not thread safe! The watches should all be
managed from the primary entrypoint thread.
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool True if the asible process is running correctly |
Source code in oper8/watch_manager/ansible_watch_manager/ansible_watch_manager.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
base
This module holds the base class interface for the various implementations of WatchManager
WatchManagerBase
Bases: ABC
A WatchManager is responsible for linking a kubernetes custom resource type with a Controller that will execute the reconciliation loop
Source code in oper8/watch_manager/base.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
__init__(controller_type)
Construct with the controller type that will be watched
Parameters:
Name | Type | Description | Default |
---|---|---|---|
controller_type
|
Type[Controller]
|
Type[Controller], The Controller instance that will manage this group/version/kind |
required |
Source code in oper8/watch_manager/base.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
__str__()
String representation of this watch
Source code in oper8/watch_manager/base.py
120 121 122 |
|
start_all()
classmethod
This utility starts all registered watches
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool True if all watches started succssfully, False otherwise |
Source code in oper8/watch_manager/base.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
stop()
abstractmethod
Terminate this watch if it is currently running
Source code in oper8/watch_manager/base.py
67 68 69 |
|
stop_all()
classmethod
This utility stops all watches
Source code in oper8/watch_manager/base.py
107 108 109 110 111 112 113 114 115 116 |
|
wait()
abstractmethod
The wait function is responsible for blocking until the managed watch has been terminated.
Source code in oper8/watch_manager/base.py
61 62 63 64 65 |
|
watch()
abstractmethod
The watch function is responsible for initializing the persistent watch and returning whether or not the watch was started successfully.
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool True if the watch was spawned correctly, False otherwise. |
Source code in oper8/watch_manager/base.py
51 52 53 54 55 56 57 58 59 |
|
dry_run_watch_manager
Dry run implementation of the WatchManager abstraction
DryRunWatchManager
Bases: WatchManagerBase
The DryRunWatchManager implements the WatchManagerBase interface with using a single shared DryRunDeployManager to manage an in-memory representation of the cluster.
Source code in oper8/watch_manager/dry_run_watch_manager.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
__init__(controller_type, deploy_manager=None)
Construct with the type of controller to watch and optionally a deploy_manager instance. A deploy_manager will be constructed if none is given.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
controller_type
|
Type[Controller]
|
Type[Controller] The class for the controller that will be watched |
required |
deploy_manager
|
Optional[DryRunDeployManager]
|
Optional[DryRunWatchManager] If given, this deploy_manager will be used. This allows for there to be pre-populated resources. Note that it must be a DryRunDeployManager (or child class) that supports registering watches. |
None
|
Source code in oper8/watch_manager/dry_run_watch_manager.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
run_reconcile(is_finalizer, resource)
Wrapper function to simplify parameter/partial mapping
Source code in oper8/watch_manager/dry_run_watch_manager.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
|
stop()
There is nothing to do in stop
Source code in oper8/watch_manager/dry_run_watch_manager.py
95 96 |
|
wait()
There is nothing to do in wait
Source code in oper8/watch_manager/dry_run_watch_manager.py
92 93 |
|
watch()
Register the watch with the deploy manager
Source code in oper8/watch_manager/dry_run_watch_manager.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
python_watch_manager
This module holds the pure-python implementation of the WatchManager
filters
init file for Filter submodule. Imports all filters, functions, and classes from filters module
common
Common functions used for interacting with filters including default filter classes
get_configured_filter()
cached
Get the default filter that should be applied to every resource
Returns:
Name | Type | Description |
---|---|---|
default_filter |
Filter
|
Filter The default filter specified in the Config |
Source code in oper8/watch_manager/python_watch_manager/filters/common.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
get_filters_for_resource_id(controller_type, resource_id)
Get the filters for a particular resource_id given a controller_type
Parameters:
Name | Type | Description | Default |
---|---|---|---|
controller_type
|
CONTROLLER_CLASS_TYPE
|
CONTROLLER_CLASS_TYPE The controller type whose filters we're inspecting |
required |
resource_id
|
RESOURCE_ID_TYPE
|
"ResourceId" The requested resource |
required |
Returns:
Name | Type | Description |
---|---|---|
filter_list |
List[Filter]
|
List[Filter] The list of filters to be applied |
Source code in oper8/watch_manager/python_watch_manager/filters/common.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
import_filter(filter_name)
Import a filter from a string reference
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter_name
|
str
|
str
Filter name in |
required |
Returns:
Name | Type | Description |
---|---|---|
imported_filter |
Filter
|
Filter The filter that was requested |
Source code in oper8/watch_manager/python_watch_manager/filters/common.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
filters
Filters are used to limit the amount of events being reconciled by a watch manager This is based off of the kubernetes controller runtime's "predicates": https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.15.0/pkg/predicate#Funcs The default set of filters is derived from operator-sdk's ansible predicates https://github.com/operator-framework/operator-sdk/blob/50c6ac03746ff4edf582feb9a71d2a7ea6ae6c40/internal/ansible/controller/controller.go#L105
AnnotationFilter
Bases: Filter
Filter resources to reconcile on annotation changes
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
|
__init__(resource)
Initialize the annotation hash variable
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
251 252 253 254 |
|
get_annotation_hash(resource)
Helper function to get the annotation hash
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
272 273 274 |
|
test(resource, event)
Test if a resource's annotation has changed
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
256 257 258 259 260 261 262 263 264 265 266 |
|
update(resource)
Update the currently stored annotation
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
268 269 270 |
|
CreationDeletionFilter
Bases: Filter
Filter to ensure reconciliation on creation and deletion events
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
test(resource, event)
Return true if event is ADDED or DELETED
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
124 125 126 127 128 129 130 131 132 133 134 135 |
|
DependentWatchFilter
Bases: Filter
Don't reconcile creation events as we can assume the owner created them
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
350 351 352 353 354 355 356 |
|
test(resource, event)
Return False if event is ADDED
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
354 355 356 |
|
DisableFilter
Bases: Filter
Filter to disable all reconciles
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
378 379 380 381 382 383 |
|
test(resource, event)
Always return False
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
381 382 383 |
|
EnableFilter
Bases: Filter
Filter to run all reconciles
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
386 387 388 389 390 391 |
|
test(resource, event)
Always return True
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
389 390 391 |
|
Filter
Bases: ABC
Generic Filter Interface for subclassing. Every subclass should implement a
test
function which returns true when a resource should be reconciled. Subclasses
can optionally implement a update
method if the filter requires storing some stateful
information like ResourceVersion or Metadata.
NOTE: A unique Filter instance is created for each resource
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
__init__(resource)
Initializer can be used to detect configuration or create instance variables. Even though a resource is provided it should not set state until update is called
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource
|
ManagedObject
|
ManagedObject This resource can be used by subclass to gather generic information. |
required |
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
44 45 46 47 48 49 50 51 52 53 |
|
test(resource, event)
abstractmethod
Test whether the resource&event passes the filter. Returns true if the filter should be reconciled and return false if it should not be. A filter can optionally return None to ignore an event
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource
|
ManagedObject
|
ManagedObject The current resource being checked |
required |
event
|
KubeEventType
|
KubeEventType The event type that triggered this filter |
required |
Returns:
Name | Type | Description |
---|---|---|
result |
Optional[bool]
|
Optional[bool] The result of the test. |
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
update(resource)
Update the instances current state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource
|
ManagedObject
|
ManagedObject The current state of the resource |
required |
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
85 86 87 88 89 90 91 |
|
update_and_test(resource, event)
First test a resource/event against a filter then update the current state
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource
|
ManagedObject
|
ManagedObject The resource being filtered |
required |
event
|
KubeEventType
|
KubeEventType The event to be filtered |
required |
Returns:
Name | Type | Description |
---|---|---|
test_result |
bool
|
bool The test result |
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
|
GenerationFilter
Bases: Filter
Filter for reconciling on generation changes for resources that support it
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
|
__init__(resource)
Set generation instance variable
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
141 142 143 144 |
|
test(resource, event)
Return true if resource generation is different than before
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
update(resource)
Update the currently observed generation
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
163 164 165 |
|
LabelFilter
Bases: Filter
Filter for resources that match a set of labels
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
|
labels()
Subclasses must implement a labels class attribute
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
365 366 367 |
|
test(resource, event)
Return true is a resource matches the requested labels
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
369 370 371 372 373 374 375 |
|
NoGenerationFilter
Bases: Filter
Filter for reconciling changes to spec on resources that don't support the generation field like pods. It does this by hashing the objects excluding status and metadata
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
__init__(resource)
Check if resource supports generation and initialize the hash dict
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
173 174 175 176 177 |
|
test(resource, event)
Return True if a resources current hash differs from the current
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
update(resource)
Update the observed spec hashes
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
202 203 204 205 206 207 208 209 210 211 212 213 |
|
PauseFilter
Bases: Filter
This filter skips resources that have the oper8 pause annotation
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
305 306 307 308 309 310 311 312 |
|
test(resource, event)
Test if a resource has the pause annotation
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
308 309 310 311 312 |
|
ResourceVersionFilter
Bases: Filter
Filter for duplicate resource versions which happens when restarting a watch connection
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
|
__init__(resource)
Initialize the resource version list
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
220 221 222 223 224 225 |
|
test(resource, event)
Test if the resource's resourceVersion has been seen before
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
227 228 229 230 231 232 233 234 235 236 237 238 |
|
update(resource)
Add the resources ResourceVersion to the list
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
240 241 242 |
|
SubsystemStatusFilter
Bases: Filter
Reconcile oper8 controllers when their oper8 status changes
This has passed basic validation but has not been rigorously tested
in the field
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
|
__init__(resource)
Initialize the currently observed ready condition
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
322 323 324 325 |
|
test(resource, event)
Test if a resources subsystem condition has changed
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
327 328 329 330 331 332 333 334 335 336 337 338 |
|
update(resource)
Update the currently observed ready condition
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
340 341 342 343 344 |
|
UserAnnotationFilter
Bases: AnnotationFilter
Filter resources to reconcile on user annotation changes. This excludes kubernetes and openshift annotations
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
|
contains_platform_key(key)
Helper to check if the key contains one of the platform annotations
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
294 295 296 297 298 299 |
|
get_annotation_hash(resource)
Overriden function to exclude common platform annotations from the annotation hash
Source code in oper8/watch_manager/python_watch_manager/filters/filters.py
282 283 284 285 286 287 288 289 290 291 292 |
|
manager
Module contains helpers for processing a group of filters
FilterManager
Bases: Filter
The FilterManager class helps process conditional filters and groups of filters. Filters that in a list are "anded" together while Filters in a tuple are "ored". This class also contains helpers to recursively convert between ClassInfo and Filters.
Source code in oper8/watch_manager/python_watch_manager/filters/manager.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
__init__(filters, resource)
Initialize all filters in the provided group
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filters
|
Union[List[Type[Filter]], Tuple[Type[Filter]]]
|
Union[List[Type[Filter]], Tuple[Type[Filter]]] The filters to manage |
required |
resource
|
ManagedObject
|
ManagedObject The initial resource |
required |
Source code in oper8/watch_manager/python_watch_manager/filters/manager.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
__recursive_filter_info(descriptor)
classmethod
Recursive helper to convert from filters to class infos and back
Parameters:
Name | Type | Description | Default |
---|---|---|---|
descriptor
|
Union[Type[Filter], Type[ClassInfo]]
|
Union[Type[Filter],Type[ClassInfo]] Either the filter or class_info to convert |
required |
Returns:
Name | Type | Description |
---|---|---|
type |
Union[Type[Filter], Type[ClassInfo]]
|
Union[Type[Filter],Type[ClassInfo]] The converted types |
Source code in oper8/watch_manager/python_watch_manager/filters/manager.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
__recursive_filter_init(filters, resource)
Helper function to recursively init each filter
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filters
|
Union[List[Type[Filter]], Tuple[Type[Filter]], Type[Filter]]
|
Union[List[Type[Filter]], Tuple[Type[Filter]], Type[Filter]] The filters to be initialized |
required |
resource
|
ManagedObject
|
ManagedObject The resource to pass to the filters |
required |
Returns: filters: Union[List[Filter], Tuple[Filter], Filter] The initalized filters
Source code in oper8/watch_manager/python_watch_manager/filters/manager.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
__recursive_map(filters, operation)
classmethod
Helper function to map an operation onto every object in a filter chain
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filters
|
Union[List[Any], Tuple[Any]]
|
Union[List[Any], Tuple[Any]] The filters to map onto |
required |
op
|
Callable[[Filter],None] The function to map onto each filter |
required |
Source code in oper8/watch_manager/python_watch_manager/filters/manager.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
__recursive_update_and_test(filters, resource, event, update_only=False, test_only=False)
Helper function to recursively update, test, or both.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filters
|
Union[list, tuple, Filter]
|
Union[list, tuple, Filter] The current filters being tested. This is updated when recurring |
required |
resource
|
ManagedObject
|
ManagedObject The current resource being updated/tested |
required |
event
|
KubeEventType
|
KubeEventType, The current event type being updated/tested |
required |
update_only
|
bool
|
bool = False Whether to only update the filters |
False
|
test_only
|
bool
|
bool = False, Whether to only test the filters |
False
|
Returns:
Name | Type | Description |
---|---|---|
result |
Optional[bool]
|
Optional[bool] The result of the tests if it was ran |
Source code in oper8/watch_manager/python_watch_manager/filters/manager.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|
from_info(info)
classmethod
Helper function to convert from ClassInfos to a filter
Parameters:
Name | Type | Description | Default |
---|---|---|---|
class_info
|
Type[ClassInfo] The classinfos to convert back into filters |
required |
Returns:
Name | Type | Description |
---|---|---|
filters |
Type[Filter]
|
Type[Filter] The converted filter objects |
Source code in oper8/watch_manager/python_watch_manager/filters/manager.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
test(resource, event)
Recursively test each filter
Source code in oper8/watch_manager/python_watch_manager/filters/manager.py
61 62 63 64 65 66 |
|
to_info(filters)
classmethod
Helper function to convert from filters to ClassInfos. This is used for pickling and IPC
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filters
|
Type[Filter]
|
Type[Filter] The filters to convert |
required |
Returns:
Name | Type | Description |
---|---|---|
class_info |
Type[ClassInfo]
|
Type[ClassInfo] The class info objects describing the filter |
Source code in oper8/watch_manager/python_watch_manager/filters/manager.py
75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
update(resource)
Update each filter recursively
Source code in oper8/watch_manager/python_watch_manager/filters/manager.py
68 69 70 71 72 73 |
|
update_and_test(resource, event)
Recursively update and test each filter
Source code in oper8/watch_manager/python_watch_manager/filters/manager.py
55 56 57 58 59 |
|
AndFilter(*args)
An "And" Filter is just a list of filters
Source code in oper8/watch_manager/python_watch_manager/filters/manager.py
22 23 24 |
|
OrFilter(*args)
An "Or" Filter is just a tuple of filters
Source code in oper8/watch_manager/python_watch_manager/filters/manager.py
27 28 29 |
|
leader_election
init file for leadership election classes. Imports all leadership managers and defines a generic helper
get_leader_election_class()
Get the current configured leadership election
Source code in oper8/watch_manager/python_watch_manager/leader_election/__init__.py
15 16 17 18 19 20 21 22 23 24 25 |
|
annotation
Annotation Based Leadership Manager
AnnotationLeadershipManager
Bases: LeadershipManagerBase
Annotation based leadership manager that uses two annotations to track leadership on a per-resource basis. This allows for horizontally scalable operations.
This has passed basic validation but has not been rigorously tested
in the field
Source code in oper8/watch_manager/python_watch_manager/leader_election/annotation.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
__init__(deploy_manager=None)
Initialize Leadership and gather current name
Parameters:
Name | Type | Description | Default |
---|---|---|---|
deploy_manager
|
DeployManagerBase
|
DeployManagerBase = None DeployManager for this Manager |
None
|
Source code in oper8/watch_manager/python_watch_manager/leader_election/annotation.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
|
acquire(force=False)
Return true as leadership is managed at resource level
Source code in oper8/watch_manager/python_watch_manager/leader_election/annotation.py
51 52 53 54 55 |
|
acquire_resource(resource)
Check a resource for leadership annotation and add one if it's expired or does not exit
Source code in oper8/watch_manager/python_watch_manager/leader_election/annotation.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
is_leader(resource=None)
Determines if current instance is leader
Source code in oper8/watch_manager/python_watch_manager/leader_election/annotation.py
139 140 141 142 143 144 145 146 147 148 149 |
|
release()
Release lock on global resource
Source code in oper8/watch_manager/python_watch_manager/leader_election/annotation.py
113 114 115 116 117 |
|
release_resource(resource)
Release lock on specific resource by removing the annotation
Source code in oper8/watch_manager/python_watch_manager/leader_election/annotation.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
base
Base classes for leader election implementations
LeadershipManagerBase
Bases: ABC
Base class for leader election. Leadership election in the PWM is split into two types: global and resource locks. Global locks are required to run any reconciliation while resource locks are required to reconcile a specific resources. Most child classes implement one of these locks.
Source code in oper8/watch_manager/python_watch_manager/leader_election/base.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
__init__(deploy_manager=None)
Initialize Class
Parameters:
Name | Type | Description | Default |
---|---|---|---|
deploy_manager
|
DeployManagerBase
|
DeployManagerBase DeployManager used in lock acquisition |
None
|
Source code in oper8/watch_manager/python_watch_manager/leader_election/base.py
30 31 32 33 34 35 36 37 38 |
|
acquire(force=False)
abstractmethod
Acquire or renew global lock
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force
|
bool
|
bool Whether to force acquire the lock irregardless of status. Used on shutdown |
False
|
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool True on successful acquisition |
Source code in oper8/watch_manager/python_watch_manager/leader_election/base.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
acquire_resource(resource)
abstractmethod
Acquire or renew lock on specific resource
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource
|
ManagedObject
|
ManagedObject Resource to acquire lock for |
required |
Returns: success: bool True on successful acquisition
Source code in oper8/watch_manager/python_watch_manager/leader_election/base.py
56 57 58 59 60 61 62 63 64 65 66 67 |
|
is_leader(resource=None)
abstractmethod
Determines if current instance is leader
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource
|
Optional[ManagedObject]
|
Optional[ManagedObject] If provided the resource to determine if current instance is leader for. If no resource if provided then the global lock is checked |
None
|
Returns: leader: bool True if instance is leader
Source code in oper8/watch_manager/python_watch_manager/leader_election/base.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
release()
abstractmethod
Release global lock
Source code in oper8/watch_manager/python_watch_manager/leader_election/base.py
69 70 71 72 73 |
|
release_resource(resource)
abstractmethod
Release lock on specific resource
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource
|
ManagedObject
|
ManagedObject Resource to release lock for |
required |
Source code in oper8/watch_manager/python_watch_manager/leader_election/base.py
75 76 77 78 79 80 81 82 83 |
|
ThreadedLeaderManagerBase
Bases: LeadershipManagerBase
Base class for threaded leadership election. This base class aids in the creation of leadership election classes that require constantly checking or updating a resource. Child classes only need to implement renew_or_acquire, and it will automatically be looped while lock acquisition is needed
Source code in oper8/watch_manager/python_watch_manager/leader_election/base.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
__init__(deploy_manager)
Initialize class with events to track leadership and shutdown and a lock to ensure renew_or_acquire is only ran once.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
deploy_manager
|
DeployManagerBase
|
DeployManagerBase DeployManager for leader election |
required |
Source code in oper8/watch_manager/python_watch_manager/leader_election/base.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
acquire(force=False)
Start/Restart leadership thread or run renew_or_acquire
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force
|
bool
|
bool=False Whether to force acquire the lock |
False
|
Returns:
Name | Type | Description |
---|---|---|
success |
bool True on successful acquisition |
Source code in oper8/watch_manager/python_watch_manager/leader_election/base.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
|
acquire_lock()
Helper function for child classes to acquire leadership lock
Source code in oper8/watch_manager/python_watch_manager/leader_election/base.py
153 154 155 156 157 158 159 160 |
|
acquire_resource(resource)
Lock in background so acquire_resource just waits for value
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource
|
ManagedObject
|
ManagedObject Resource that is being locked |
required |
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool True on successful acquisition else False |
Source code in oper8/watch_manager/python_watch_manager/leader_election/base.py
203 204 205 206 207 208 209 210 211 212 213 214 215 |
|
is_leader(resource=None)
Return if leader event has been acquired
Returns:
Name | Type | Description |
---|---|---|
leader |
bool
|
bool If instance is current leader |
Source code in oper8/watch_manager/python_watch_manager/leader_election/base.py
231 232 233 234 235 236 237 238 239 |
|
release()
Release lock and shutdown leader election thread. This thread first shuts down the background thread before clearing the lock
Source code in oper8/watch_manager/python_watch_manager/leader_election/base.py
217 218 219 220 221 222 223 224 |
|
release_lock()
Helper function for child classes to release lock
Source code in oper8/watch_manager/python_watch_manager/leader_election/base.py
162 163 164 165 166 167 168 |
|
release_resource(resource)
Release resource is not implemented in Threaded classes
Source code in oper8/watch_manager/python_watch_manager/leader_election/base.py
226 227 228 229 |
|
renew_or_acquire()
Renew or acquire leadership lock
Source code in oper8/watch_manager/python_watch_manager/leader_election/base.py
147 148 149 150 151 |
|
run()
Loop to continuously run renew or acquire every so often
Source code in oper8/watch_manager/python_watch_manager/leader_election/base.py
243 244 245 246 247 248 249 250 251 252 253 |
|
run_renew_or_acquire()
Run renew_or_acquire safely and with threaded lock
Source code in oper8/watch_manager/python_watch_manager/leader_election/base.py
255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
dry_run
Implementation of the DryRun LeaderElection
DryRunLeadershipManager
Bases: LeadershipManagerBase
DryRunLeaderElection class implements an empty leadership election manager which always acts as a leader. This is useful for dryrun or running without leadership election
Source code in oper8/watch_manager/python_watch_manager/leader_election/dry_run.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
acquire(force=False)
Return true as dryrun is always leader
Source code in oper8/watch_manager/python_watch_manager/leader_election/dry_run.py
15 16 17 18 19 |
|
acquire_resource(resource)
Return true as dryrun is always leader
Source code in oper8/watch_manager/python_watch_manager/leader_election/dry_run.py
21 22 23 24 25 |
|
is_leader(resource=None)
DryRunLeadershipManager is always leader
Source code in oper8/watch_manager/python_watch_manager/leader_election/dry_run.py
37 38 39 40 41 |
|
release()
NoOp in DryRun as lock is not real
Source code in oper8/watch_manager/python_watch_manager/leader_election/dry_run.py
27 28 29 30 |
|
release_resource(resource)
NoOp in DryRun as lock is not real
Source code in oper8/watch_manager/python_watch_manager/leader_election/dry_run.py
32 33 34 35 |
|
lease
Implementation of the Leader-with-Lease LeaderElection
LeaderWithLeaseManager
Bases: ThreadedLeaderManagerBase
LeaderWithLeaseManager Class implements the "leader-with-lease" operator-sdk lock type. This lock creates a lease object with the operator pod as owner and constantly re-acquires the lock.
Source code in oper8/watch_manager/python_watch_manager/leader_election/lease.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
__init__(deploy_manager)
Initialize class with lock_name, current namespace, and pod information
Source code in oper8/watch_manager/python_watch_manager/leader_election/lease.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
renew_or_acquire()
Renew or acquire lock by checking the current lease status
Source code in oper8/watch_manager/python_watch_manager/leader_election/lease.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
life
Implementation of the Leader-for-Life LeaderElection
LeaderForLifeManager
Bases: ThreadedLeaderManagerBase
LeaderForLifeManager Class implements the old "leader-for-life" operator-sdk lock type. This lock creates a configmap with the operator pod as owner in the current namespace. This way when the pod is deleted or list so is the configmap.
Source code in oper8/watch_manager/python_watch_manager/leader_election/life.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
__init__(deploy_manager)
Initialize class with lock_name, current namespace, and pod information
Source code in oper8/watch_manager/python_watch_manager/leader_election/life.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|
renew_or_acquire()
Renew or acquire lock by checking the current configmap status
Source code in oper8/watch_manager/python_watch_manager/leader_election/life.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
python_watch_manager
Python-based implementation of the WatchManager
PythonWatchManager
Bases: WatchManagerBase
The PythonWatchManager uses the kubernetes watch client to watch a particular Controller and execute reconciles. It does the following two things
- Request a generic watch request for each namespace
- Start a reconcile thread to start reconciliation subprocesses
Source code in oper8/watch_manager/python_watch_manager/python_watch_manager.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
__init__(controller_type, deploy_manager=None, namespace_list=None)
Initialize the required threads and submit the watch requests Args: controller_type: Type[Controller] The controller to be watched deploy_manager: Optional[OpenshiftDeployManager] = None An optional DeployManager override namespace_list: Optional[List[str]] = [] A list of namespaces to watch
Source code in oper8/watch_manager/python_watch_manager/python_watch_manager.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
stop()
Stop all threads. This waits for all reconciles to finish
Source code in oper8/watch_manager/python_watch_manager/python_watch_manager.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
wait()
Wait shutdown to be signaled
Source code in oper8/watch_manager/python_watch_manager/python_watch_manager.py
119 120 121 |
|
watch()
Check for leadership and start all threads
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool True if all threads process are running correctly |
Source code in oper8/watch_manager/python_watch_manager/python_watch_manager.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
reconcile_process_entrypoint
ReconcileProcessEntrypoint for all PWM reconciles
ReconcileProcessDeployManager
Bases: OpenshiftDeployManager
ReconcileProcessEntrypoint deploy manager is a helper deploy manager that allows the PWM to insert functionality during a reconcile. This is used for things like watching dependent resources and subsystem rollout
Source code in oper8/watch_manager/python_watch_manager/reconcile_process_entrypoint.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
__init__(controller_type, controller_resource, result_pipe, *args, **kwargs)
Initalize the ReconcileProcessEntrypoint DeployManger and gather start-up configurations
Parameters:
Name | Type | Description | Default |
---|---|---|---|
controller_type
|
Type[Controller]
|
Type[Controller] The Controller being reconciled |
required |
controller_resource
|
Config
|
aconfig.Config The resource being reconciled |
required |
result_pipe
|
Connection
|
Connection The pipe to send dependent watch requests to |
required |
*args
|
Extendable arguments to pass to to parent |
()
|
|
**kwargs
|
Extendable key word arguments to pass to parent |
{}
|
Source code in oper8/watch_manager/python_watch_manager/reconcile_process_entrypoint.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
ReconcileProcessEntrypoint
The ReconcileProcessEntrypoint Class is the main start place for a reconciliation. It configures some watch manager specific settings like multiprocess logging, and signal handling then it hands off control to the ReconcileManager
Source code in oper8/watch_manager/python_watch_manager/reconcile_process_entrypoint.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
|
__init__(controller_type, deploy_manager=None)
Initializer for the entrypoint class
Parameters:
Name | Type | Description | Default |
---|---|---|---|
controller_type
|
Type[Controller]
|
Type[Controller] The Controller type being reconciled |
required |
deploy_manager
|
DeployManagerBase
|
DeployManagerBase = None An optional deploy manager override |
None
|
Source code in oper8/watch_manager/python_watch_manager/reconcile_process_entrypoint.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
|
start(request, result_pipe)
Main entrypoint for the class
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request
|
ReconcileRequest
|
ReconcileRequest The reconcile request that trigger this reconciliation |
required |
result_pipe
|
Connection
|
Connection The connection to send results back to |
required |
Source code in oper8/watch_manager/python_watch_manager/reconcile_process_entrypoint.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
|
create_and_start_entrypoint(logging_queue, request, result_pipe, deploy_manager=None)
Function to create and start an entrypoint while catching any unexpected errors Args: logging_queue: multiprocessing.Queue The queue to send log messages to request: ReconcileRequest The request that triggered this reconciliation result_pipe: Connection The pipe to send a result back with deploy_manager: DeployManagerBase = None An optional DeployManager override
Source code in oper8/watch_manager/python_watch_manager/reconcile_process_entrypoint.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
|
threads
Import the ThreadBase and subclasses
base
Module for the ThreadBase Class
ThreadBase
Bases: Thread
Base class for all other thread classes. This class handles generic starting, stopping, and leadership functions
Source code in oper8/watch_manager/python_watch_manager/threads/base.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
__init__(name=None, daemon=None, deploy_manager=None, leadership_manager=None)
Initialize class and store required instance variables. This function is normally overriden by subclasses that pass in static name/daemon variables
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
str=None The name of the thread to manager |
None
|
daemon
|
bool
|
bool=None Whether python should wait for this thread to stop before exiting |
None
|
deploy_manager
|
DeployManagerBase
|
DeployManagerBase = None The deploy manager available to this thread during start() |
None
|
leadership_manager
|
LeadershipManagerBase
|
LeadershipManagerBase = None The leadership_manager for tracking elections |
None
|
Source code in oper8/watch_manager/python_watch_manager/threads/base.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
check_preconditions()
Helper function to check if the thread should shutdown or reacquire leadership
Source code in oper8/watch_manager/python_watch_manager/threads/base.py
77 78 79 80 81 82 83 84 85 86 |
|
run()
Control loop for the thread. Once this function exits the thread stops
Source code in oper8/watch_manager/python_watch_manager/threads/base.py
51 52 53 |
|
should_stop()
Helper to determine if a thread should shutdown
Source code in oper8/watch_manager/python_watch_manager/threads/base.py
73 74 75 |
|
start_thread()
If the thread is not already alive start it
Source code in oper8/watch_manager/python_watch_manager/threads/base.py
62 63 64 65 66 |
|
stop_thread()
Set the shutdown event
Source code in oper8/watch_manager/python_watch_manager/threads/base.py
68 69 70 71 |
|
wait_on_precondition(timeout)
Helper function to allow threads to wait for a certain period of time only being interrupted for preconditions
Source code in oper8/watch_manager/python_watch_manager/threads/base.py
88 89 90 91 92 93 |
|
heartbeat
Thread class that will dump a heartbeat to a file periodically
HeartbeatThread
Bases: TimerThread
The HeartbeatThread acts as a pulse for the PythonWatchManager.
This thread will periodically dump the value of "now" to a file which can be read by an observer such as a liveness/readiness probe to ensure that the manager is functioning well.
Source code in oper8/watch_manager/python_watch_manager/threads/heartbeat.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
__init__(heartbeat_file, heartbeat_period)
Initialize with the file location for the heartbeat output
Parameters:
Name | Type | Description | Default |
---|---|---|---|
heartbeat_file
|
str
|
str The fully-qualified path to the heartbeat file |
required |
heartbeat_period
|
str
|
str
Time delta string representing period delay between beats.
NOTE: The GNU |
required |
Source code in oper8/watch_manager/python_watch_manager/threads/heartbeat.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
wait_for_beat()
Wait for the next beat
Source code in oper8/watch_manager/python_watch_manager/threads/heartbeat.py
53 54 55 56 57 58 59 60 61 |
|
reconcile
The ReconcileThread is the heart of the PythonWatchManager and controls reconciling resources and managing any subprocesses
ReconcileThread
Bases: ThreadBase
This class is the core reconciliation class that handles starting subprocesses, tracking their status, and handles any results. This thread also kicks of requeue requests and requests dependent resource watches
Source code in oper8/watch_manager/python_watch_manager/threads/reconcile.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
|
__init__(deploy_manager=None, leadership_manager=None)
Initialize the required queues, helper threads, and reconcile tracking. Also gather any onetime configuration options
Parameters:
Name | Type | Description | Default |
---|---|---|---|
deploy_manager
|
DeployManagerBase
|
DeployManagerBase = None The deploy manager used throughout the thread |
None
|
leadership_manager
|
LeadershipManagerBase
|
LeadershipManagerBase = None The leadership_manager for tracking elections |
None
|
Source code in oper8/watch_manager/python_watch_manager/threads/reconcile.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|
push_request(request)
Push request to reconcile queue
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request
|
ReconcileRequest
|
ReconcileRequest the ReconcileRequest to add to the queue |
required |
Source code in oper8/watch_manager/python_watch_manager/threads/reconcile.py
215 216 217 218 219 220 221 222 223 224 225 226 227 |
|
run()
The reconcile threads control flow is to first wait for either a new reconcile request or for a process to end. If its a reconcile request the thread checks if one is already running for the resource and if not starts a new one. If a reconcile is already running or the thread couldn't start a new one the request gets added to the pending reconciles. There can only be one pending reconcile per resource. If the reconcile thread received a process end event it checks the exit code and handles the result queue.
Source code in oper8/watch_manager/python_watch_manager/threads/reconcile.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
start_thread()
Override start_thread to start helper threads
Source code in oper8/watch_manager/python_watch_manager/threads/reconcile.py
165 166 167 168 169 |
|
stop_thread()
Override stop_thread to ensure reconciles finish correctly
Source code in oper8/watch_manager/python_watch_manager/threads/reconcile.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
timer
The TimerThread is a helper class used to run schedule events
TimerThread
Bases: ThreadBase
The TimerThread class is a helper class to run scheduled actions. This is very similar to threading.Timer stdlib class except that it uses one shared thread for all events instead of a thread per event.
Source code in oper8/watch_manager/python_watch_manager/threads/timer.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
|
__init__(name=None)
Initialize a priorityqueue like object and a synchronization object
Source code in oper8/watch_manager/python_watch_manager/threads/timer.py
27 28 29 30 31 32 33 34 35 |
|
put_event(time, action, *args, **kwargs)
Push an event to the timer
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time
|
datetime
|
datetime The datetime to execute the event at |
required |
action
|
Callable
|
Callable The action to execute |
required |
*args
|
Any
|
Any Args to pass to the action |
()
|
**kwargs
|
Dict
|
Dict Kwargs to pass to the action |
{}
|
Returns:
Name | Type | Description |
---|---|---|
event |
Optional[TimerEvent]
|
Optional[TimerEvent] TimerEvent describing the event and can be cancelled |
Source code in oper8/watch_manager/python_watch_manager/threads/timer.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
run()
The TimerThread's control loop sleeps until the next schedule event and executes all pending actions.
Source code in oper8/watch_manager/python_watch_manager/threads/timer.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
stop_thread()
Override stop_thread to wake the control loop
Source code in oper8/watch_manager/python_watch_manager/threads/timer.py
66 67 68 69 70 71 72 73 |
|
watch
The WatchThread Class is responsible for monitoring the cluster for resource events
WatchThread
Bases: ThreadBase
The WatchThread monitors the cluster for changes to a specific GroupVersionKind either cluster-wide or for a particular namespace. When it detects a change it checks the event against the registered Filters and submits a ReconcileRequest if it passes. Every resource that has at least one watch request gets a corresponding WatchedResource object whose main job is to store the current Filter status
Source code in oper8/watch_manager/python_watch_manager/threads/watch.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
|
__init__(reconcile_thread, kind, api_version, namespace=None, deploy_manager=None, leadership_manager=None)
Initialize a WatchThread by assigning instance variables and creating maps
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reconcile_thread
|
RECONCILE_THREAD_TYPE
|
ReconcileThread The reconcile thread to submit requests to |
required |
kind
|
str
|
str The kind to watch |
required |
api_version
|
str
|
str The api_version to watch |
required |
namespace
|
Optional[str]
|
Optional[str] = None The namespace to watch. If none then cluster-wide |
None
|
deploy_manager
|
DeployManagerBase
|
DeployManagerBase = None The deploy_manager to watch events |
None
|
leadership_manager
|
LeadershipManagerBase
|
LeadershipManagerBase = None The leadership manager to use for elections |
None
|
Source code in oper8/watch_manager/python_watch_manager/threads/watch.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
request_watch(watch_request)
Add a watch request if it doesn't exist
Parameters:
Name | Type | Description | Default |
---|---|---|---|
watch_request
|
WatchRequest
|
WatchRequest The watch_request to add |
required |
Source code in oper8/watch_manager/python_watch_manager/threads/watch.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
run()
The WatchThread's control loop continuously watches the DeployManager for any new
events. For every event it gets it gathers all the WatchRequests whose watched
value
applies. The thread then initializes a WatchedObject if one doesn't already exist and
tests the event against each request's Filter. Finally, it submits a ReconcileRequest
for all events that pass
Source code in oper8/watch_manager/python_watch_manager/threads/watch.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
|
stop_thread()
Override stop_thread to stop the kubernetes client's Watch as well
Source code in oper8/watch_manager/python_watch_manager/threads/watch.py
196 197 198 199 |
|
create_resource_watch(watch_request, reconcile_thread, deploy_manager, leadership_manager)
Create or request a watch for a resource. This function will either append the request to an existing thread or create a new one. This function will also start the thread if any other watch threads have already been started.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
watch_request
|
WatchRequest
|
WatchRequest The watch request to submit |
required |
reconcile_thread
|
RECONCILE_THREAD_TYPE
|
ReconcileThread The ReconcileThread to submit ReconcileRequests to |
required |
deploy_manager
|
DeployManagerBase
|
DeployManagerBase The DeployManager to use with the Thread |
required |
leadership_manager
|
LeadershipManagerBase
|
LeadershipManagerBase The LeadershipManager to use for election |
required |
Returns:
Name | Type | Description |
---|---|---|
watch_thread |
WatchThread
|
WatchThread The watch_thread that is watching the request |
Source code in oper8/watch_manager/python_watch_manager/threads/watch.py
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 |
|
get_resource_watches()
Get the list of all watch_threads
Returns:
Name | Type | Description |
---|---|---|
list_of_watches |
List[WatchThread]
|
List[WatchThread] List of watch threads |
Source code in oper8/watch_manager/python_watch_manager/threads/watch.py
506 507 508 509 510 511 512 513 |
|
utils
Import All functions, constants, and class from utils module
common
Shared utilities for the PythonWatchManager
get_logging_handlers()
Get the current logging handlers
Source code in oper8/watch_manager/python_watch_manager/utils/common.py
98 99 100 101 102 103 104 105 |
|
get_operator_namespace()
Get the current namespace from a kubernetes file or config
Source code in oper8/watch_manager/python_watch_manager/utils/common.py
59 60 61 62 63 64 65 66 67 |
|
get_pod_name()
Get the current pod from env variables, config, or hostname
Source code in oper8/watch_manager/python_watch_manager/utils/common.py
70 71 72 73 74 75 76 77 78 |
|
obj_to_hash(obj)
Get the hash of any jsonable python object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
Any The object to hash |
required |
Returns:
Name | Type | Description |
---|---|---|
hash |
str
|
str The hash of obj |
Source code in oper8/watch_manager/python_watch_manager/utils/common.py
84 85 86 87 88 89 90 91 92 93 94 95 |
|
parse_time_delta(time_str)
Parse a string into a timedelta. Excepts values in the following formats: 1h, 5m, 10s, etc
Parameters:
Name | Type | Description | Default |
---|---|---|---|
time_str
|
str
|
str The string representation of a timedelta |
required |
Returns:
Name | Type | Description |
---|---|---|
result |
Optional[timedelta]
|
Optional[timedelta] The parsed timedelta if one could be found |
Source code in oper8/watch_manager/python_watch_manager/utils/common.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
constants
Useful Constants
log_handler
Log handler helper class
LogQueueHandler
Bases: QueueHandler
Log Handler class to collect messages from a child processes and pass them to the root process via a multiprocess queue
Source code in oper8/watch_manager/python_watch_manager/utils/log_handler.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
__init__(queue, manifest=None)
Initialize the queue handler and instance variables
Parameters:
Name | Type | Description | Default |
---|---|---|---|
queue
|
QUEUE_TYPE
|
"Queue[Any]" The queue to pass messages to |
required |
manifest
|
ManagedObject
|
ManagedObject The manifest of the current process. This is only used if it can't find the resource on the current formatter |
None
|
Source code in oper8/watch_manager/python_watch_manager/utils/log_handler.py
26 27 28 29 30 31 32 33 34 35 36 37 |
|
prepare(record)
Prep a record for pickling before sending it to the queue
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record
|
LogRecord
|
LogRecord The record to be prepared |
required |
Returns:
Name | Type | Description |
---|---|---|
prepared_record |
LogRecord
|
LogRecord The prepared record ready to be pickled |
Source code in oper8/watch_manager/python_watch_manager/utils/log_handler.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
types
Standard data types used through PWM
ABCSingletonMeta
Bases: Singleton
, ABCMeta
Shared metaclass for ABCMeta and Singleton
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
273 274 |
|
ClassInfo
Bases: NamedTuple
Class containing information describing a class. This is required when passing class references between processes which might have different sys paths like when using VCS
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
from_obj(obj)
classmethod
Create a ClassInfo from an existing object
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
115 116 117 118 |
|
from_type(class_obj)
classmethod
Create a ClassInfo from a class object
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
110 111 112 113 |
|
to_class()
Import and return a ClassInfo's type
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
121 122 123 124 125 126 127 128 129 130 131 132 |
|
ReconcileProcess
dataclass
Dataclass to track a running reconcile. This includes the raw process object, the result pipe, and the request being reconciled
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|
fileno()
Pass through fileno to process. Sentinel so this object can be directly used by multiprocessing.connection.wait
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
225 226 227 228 |
|
uid()
Get the uid for the resource being reconciled
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
230 231 232 |
|
ReconcileRequest
dataclass
Class to represent one request to the ReconcileThread. This includes important information including the current resource and Controller being reconciled.
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
uid()
Get the uid of the resource being reconciled
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
211 212 213 |
|
ReconcileRequestType
Bases: Enum
Enum to expand the possible KubeEventTypes to include PythonWatchManager specific events
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
ResourceId
dataclass
Class containing the information needed to identify a resource
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
global_id
cached
property
Get the global_id for a resource in the form kind.version.group
namespaced_id
cached
property
Get the namespace specific id for a resource
from_controller(controller, namespace=None)
classmethod
Get a Controller's target as a resource id
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
87 88 89 90 91 92 93 94 95 96 |
|
from_owner_ref(owner_ref, namespace=None)
classmethod
Create a resource id from an ownerRef
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
77 78 79 80 81 82 83 84 85 |
|
from_resource(resource)
classmethod
Create a resource id from an existing resource
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
66 67 68 69 70 71 72 73 74 75 |
|
get_id()
Get the requisite id for a resource
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
49 50 51 |
|
get_named_id()
Get a named id for a resouce
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
53 54 55 |
|
get_resource()
Get a resource template from this id
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
57 58 59 60 61 62 63 |
|
Singleton
Bases: type
MetaClass to limit a class to only one global instance. When the first instance is created it's attached to the Class and the next time someone initializes the class the original instance is returned
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
|
TimerEvent
dataclass
Class for keeping track of an item in the timer queue. Time is the only comparable field to support the TimerThreads priority queue
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
|
cancel()
Cancel this event. It will not be executed when read from the queue
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
247 248 249 250 |
|
WatchRequest
dataclass
A class for requesting a watch of a particular object. It contains information around the watched object, who requested the watch, the controller type to be reconciled, and any filters to be applied to just this request
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
WatchedResource
dataclass
A class for tracking a resource in the cluster. Every resource that has a requested watch will have a corresponding WatchedResource
Source code in oper8/watch_manager/python_watch_manager/utils/types.py
135 136 137 138 139 140 141 142 143 144 145 |
|
x
The oper8.x module holds common implementations of reusable patterns built on top of the abstractions in oper8. These are intended as reusable components that can be share across many operator implementations.
One of the core principles of oper8 is that the schema for config is entirely up to the user (with the only exception being spec.version). In oper8.x, this is not the case and there are many config conventions (CRD schema and backend) that are encoded into the various utilities.
datastores
connection_base
Base class definition for all datastore connections
DatastoreConnectionBase
Bases: ABCStatic
A DatastoreConnection is an object that holds all of the critical data to connect to a specific datastore type. A DatastoreConnection for a given datastore type MUST not care what implementation backs the connection.
Source code in oper8/x/datastores/connection_base.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
__init__(session)
Construct with the session so that it can be saved as a member
Source code in oper8/x/datastores/connection_base.py
29 30 31 |
|
from_dict(session, config_dict)
abstractmethod
classmethod
Parse a config_dict from a subsystem CR to create an instance of the DatastoreConnection class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The current deploy session |
required |
config_dict
|
dict
|
dict This dict will hold the keys and values created by to_dict and pulled from the subsystem CR. |
required |
Returns:
Name | Type | Description |
---|---|---|
datastore_connection |
DatastoreConnectionBase
|
DatastoreConnectionBase The constructed instance of the connection |
Source code in oper8/x/datastores/connection_base.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
to_dict()
abstractmethod
Serialize the internal connection details to a dict object which can be added directly to a subsystem's CR.
Returns:
Name | Type | Description |
---|---|---|
config_dict |
dict
|
dict This dict will hold the keys and values that can be used to add to a subsystem's datastores.connections section. |
Source code in oper8/x/datastores/connection_base.py
39 40 41 42 43 44 45 46 47 48 |
|
cos
Top level imports for the cos datastore type
connection
The common Connection type for a COS instance
CosConnection
Bases: DatastoreConnectionBase
A CosConnection holds the core connection information for a named COS instance, regardless of what ICosComponent implements it. The key pieces of information are:
-
General config
- hostname: The hostname where the instance can be reached
- port: The port where the instance is listening
- bucket_name: The name of the bucket within the instance
-
Auth
- auth_secret_name: The in-cluster name for the secret holding the access_key and secret_key
- auth_secret_access_key_field: The field within the auth secret that holds the access_key
- auth_secret_secret_key_field: The field within the auth secret that holds the secret_key
-
TLS:
- tls_cert: The content of the TLS cert if tls is enabled
- tls_secret_name: The in-cluster name for the secret holding the TLS creds if tls is enabled
- tls_secret_cert_field: The field within the tls secret that holds the cert
Source code in oper8/x/datastores/cos/connection.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
|
auth_secret_access_key_field
property
Field in the auth secret containing the access_key
auth_secret_name
property
Secret name containing the access_key and secret_key
auth_secret_secret_key_field
property
Field in the auth secret containing the secret_key
bucket_name
property
The numeric bucket_name
endpoint
property
The fully constructed endpoint for the COS instance
hostname
property
The hostname (without schema)
port
property
The numeric port
schema
property
The schema (http or https)
tls_secret_cert_field
property
The field within the tls secret that holds the CA cert
tls_secret_name
property
The name of the secret holding the tls certificate (for mounting)
get_auth_keys()
Get the current access_key/secret_key pair from the auth secret if available
Returns:
Name | Type | Description |
---|---|---|
access_key |
Optional[str]
|
str or None The plain-text access_key (not encoded) if available |
secret_key |
Optional[str]
|
str or None The plain-text secret_key (not encoded) if available |
Source code in oper8/x/datastores/cos/connection.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
|
get_connection_string()
Get the formatted s3 connection string to connect to the given bucket in the instance
Returns:
Name | Type | Description |
---|---|---|
connection_string |
str
|
str The formatted connection string |
Source code in oper8/x/datastores/cos/connection.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
|
get_tls_cert()
Get the current TLS certificate for a client connection if TLS is enabled
If TLS is enabled, but the cert is not found, this function will raise an AssertionError
Returns:
Name | Type | Description |
---|---|---|
tls_cert |
Optional[str]
|
str or None PEM encoded cert string (not base64-encoded) if found, otherwise None |
Source code in oper8/x/datastores/cos/connection.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
|
to_dict()
Return the dict representation of the object for the CR
Source code in oper8/x/datastores/cos/connection.py
165 166 167 |
|
factory
COS instance factory
CosFactory
Bases: DatastoreSingletonFactoryBase
The common factory that will manage instances of COS for each deploy
Source code in oper8/x/datastores/cos/factory.py
10 11 12 13 14 |
|
interfaces
Base class interface for a Cloud Object Store (cos) component
ICosComponentBase
Bases: Datastore
A COS chart provides access to a single running S3-compatible object store instance
Source code in oper8/x/datastores/cos/interfaces.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
get_connection()
Get the connection object for this instance
Source code in oper8/x/datastores/cos/interfaces.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|
factory_base
The DatastoreSingletonFactoryBase class defines the common functionality that all datastore type factories will use. It implements common logic for constructing named singleton instances of a given datastore type.
DatastoreSingletonFactoryBase
The DatastoreSingletonFactoryBase manages instances of all datastore types as singletons on a per-deployment basis. It provides functionality for derived classes to define a specific DATASTORE_TYPE (e.g. redis) and register implementations of that type.
The instances of each type are held as singletons scoped to the individual deployment (session.deploy_id). This is done to support multiple calls to fetch a named instance within a given deployment without reconstructing, but to allow configuration to change between deploys.
Source code in oper8/x/datastores/factory_base.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
|
get_component(session, name=None, disabled=False, config_overrides=None)
classmethod
Construct an instance of the datastore type's component
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The session for the current deployment |
required |
name
|
Optional[str]
|
Optional[str] The name of the singleton instance to get. If not provided, a top-level instance is used (e.g. datastores.postgres.type) |
None
|
disabled
|
bool
|
bool Whether or not the component is disabled in this deployment |
False
|
config_overrides
|
Optional[dict]
|
Optional[dict] Optional runtime config values. These will overwrite any values pulled from the session.config |
None
|
Returns:
Name | Type | Description |
---|---|---|
instance |
Optional[Component]
|
Optional[Component] The constructed component if one is needed |
Source code in oper8/x/datastores/factory_base.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
get_connection(session, name=None, allow_from_component=True)
classmethod
Get the connection details for a named instance of the datastore type
If not pre-constructed by the creation of the Component, connection
details are pulled from the CR directly
(spec.datastores.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The session for the current deployment |
required |
name
|
Optional[str]
|
Optional[str] The name of the singleton instance to get. If not provided, a top-level instance is used |
None
|
allow_from_component
|
bool
|
bool If True, use connection info from the component |
True
|
Returns:
Name | Type | Description |
---|---|---|
connection |
DatastoreConnectionBase
|
DatastoreConnectionBase The connection for this instance |
Source code in oper8/x/datastores/factory_base.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
register_type(type_class)
classmethod
Register a new type constructor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_class
|
Datastore
|
Datastore The class that will be constructed with the config for |
required |
Source code in oper8/x/datastores/factory_base.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
|
classproperty
@classmethod+@property CITE: https://stackoverflow.com/a/22729414
Source code in oper8/x/datastores/factory_base.py
25 26 27 28 29 30 31 32 33 34 |
|
interfaces
Base class for all Datastore component implementations
Datastore
Bases: Oper8xComponent
The Datastore baseclass defines the interface that any datastore must conform to. It is a oper8 Component and should be constructed via a per-type factory.
Source code in oper8/x/datastores/interfaces.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
config
property
The config for this instance of the datastore
__init__(session, config, instance_name=None, disabled=False)
This passthrough constructor enforces that all datastores have a class attribute TYPE_LABEL (str)
Source code in oper8/x/datastores/interfaces.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
get_connection()
abstractmethod
Get the connection object for this datastore instance. Each datastore type must manage a common abstraction for a connection which clients will use to connect to the datastore.
Source code in oper8/x/datastores/interfaces.py
50 51 52 53 54 55 |
|
postgres
Common postgres module exposed imports
connection
The common Connection type for a postgres instance
PostgresConnection
Bases: DatastoreConnectionBase
A connection for postgres defines the client operations and utilities needed to configure a microservice to interact with a single postgres instance. The key pieces of information are:
-
General config:
- hostname: The hostname where the database can be reached
- port: The port the database service is listening on
-
Auth:
- auth_secret_name: The in-cluster name for the secret holding the username and password
- auth_secret_username_field: The field within the auth secret that holds the username
- auth_secret_password_field: The field within the auth secret that holds the password
-
TLS:
- tls_cert: The content of the TLS cert if tls is enabled
- tls_secret_name: The in-cluster name for the secret holding the TLS creds if tls is enabled
- tls_secret_cert_field: The field within the tls secret that holds the cert
Source code in oper8/x/datastores/postgres/connection.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
|
__init__(session, hostname, port, auth_secret_name, auth_secret_username_field, auth_secret_password_field, tls_secret_name=None, tls_secret_cert_field=None, auth_username=None, auth_password=None, tls_cert=None)
Construct with all of the crucial information pieces
Source code in oper8/x/datastores/postgres/connection.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
|
get_auth_username_password()
Get the current username/password pair from the auth secret if available
Returns:
Name | Type | Description |
---|---|---|
username |
str
|
str or None The plain-text username for the instance or None if not available |
password |
str
|
str or None The plain-text password for the instance or None if not available |
Source code in oper8/x/datastores/postgres/connection.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
get_ssl_mode()
Get Postgres SSL mode to operate in
Returns:
Name | Type | Description |
---|---|---|
ssl_mode |
str
|
str "require" (tls enabled) or "disable" (tls disabled) |
Source code in oper8/x/datastores/postgres/connection.py
192 193 194 195 196 197 198 199 |
|
get_tls_cert()
Get the current TLS certificate for a client connection if TLS is enabled
If TLS is enabled, but the cert is not found, this function will raise an AssertionError
Returns:
Name | Type | Description |
---|---|---|
tls_cert |
Optional[str]
|
str or None PEM encoded cert string (not base64-encoded) if found, otherwise None |
Source code in oper8/x/datastores/postgres/connection.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
|
get_tls_secret_volume_mounts(mount_path=DEFAULT_TLS_VOLUME_MOUNT_PATH, volume_name=DEFAULT_TLS_VOLUME_NAME)
Get the list of volumeMounts entries needed to support TLS for a client. If TLS is not enabled, this will be an empty list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mount_path
|
str
|
str A path where the tls entries should be mounted |
DEFAULT_TLS_VOLUME_MOUNT_PATH
|
volume_name
|
str
|
str The name of the volume within the pod spec |
DEFAULT_TLS_VOLUME_NAME
|
Returns:
Name | Type | Description |
---|---|---|
volume_mounts |
List[dict]
|
List[dict] A list of dict entries for the volume mounts which can be used to extend other volume lists |
Source code in oper8/x/datastores/postgres/connection.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
|
get_tls_secret_volumes(cert_mount_path=None, volume_name=DEFAULT_TLS_VOLUME_NAME)
Get the list of dict entries needed to support TLS for a client. If TLS is not enabled, this will be an empty list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cert_mount_path
|
Optional[str]
|
Optional[str] The name of the file that the ca cert should be mounted to |
None
|
volume_name
|
str
|
str The name of the volume within the pod spec |
DEFAULT_TLS_VOLUME_NAME
|
Returns:
Name | Type | Description |
---|---|---|
volumes |
List[dict]
|
List[dict] A list of dict Volume entries which can be used to extend other volume lists |
Source code in oper8/x/datastores/postgres/connection.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
to_dict()
Return the dict representation of the object for the CR
Source code in oper8/x/datastores/postgres/connection.py
144 145 146 |
|
factory
Postgres instance factory
PostgresFactory
Bases: DatastoreSingletonFactoryBase
The common factory that will manage instances of Postgres for each deploy
Source code in oper8/x/datastores/postgres/factory.py
10 11 12 13 14 |
|
interfaces
Base class interface for a Postgres component
IPostgresComponent
Bases: Datastore
A postgres chart provides access to a single running Postgres cluster
Source code in oper8/x/datastores/postgres/interfaces.py
12 13 14 15 16 17 18 19 20 21 22 23 |
|
tls_enabled()
Return whether TLS is enabled or not Returns: bool: True (TLS enabled), False (TLS disabled)
Source code in oper8/x/datastores/postgres/interfaces.py
18 19 20 21 22 23 |
|
redis
Top level imports for the Redis datastore type
connection
The common connection type for a Redis instance
RedisConnection
Bases: DatastoreConnectionBase
A RedisConnection holds the core connection information for a named Redis instance, regardless of what IRedisComponent implements it. The key pieces of information are:
-
General config
- hostname: The hostname where the instance can be reached
- port: The port where the instance is listening
-
Auth
- auth_secret_name: The in-cluster name for the secret holding the username and password
- auth_secret_username_field: The field within the auth secret that holds the username.
- auth_secret_password_field: The field within the auth secret that holds the password
-
TLS:
- tls_cert: The content of the TLS cert if tls is enabled
- tls_secret_name: The in-cluster name for the secret holding the TLS creds if tls is enabled
- tls_secret_cert_field: The field within the tls secret that holds the cert
Source code in oper8/x/datastores/redis/connection.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
|
auth_secret_name
property
Secret name containing the username_key and password_key
auth_secret_password_field
property
Field in the auth secret containing the password
auth_secret_username_field
property
Field in the auth secret containing the username
hostname
property
The hostname (without schema)
port
property
The numeric port
schema
property
The schema (redis or rediss)
tls_secret_cert_field
property
The field within the tls secret that holds the CA cert
tls_secret_name
property
The name of the secret holding the tls certificate (for mounting)
get_auth_username_password()
Get the current username_key/password_key pair from the auth secret if available
Returns:
Name | Type | Description |
---|---|---|
username |
Optional[str]
|
str or None The plain-text username (not encoded) if available |
password |
Optional[str]
|
str or None The plain-text password (not encoded) if available |
Source code in oper8/x/datastores/redis/connection.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
|
get_connection_string()
Get the formatted Redis connection string to connect to the instance
Returns:
Name | Type | Description |
---|---|---|
connection_string |
str
|
str The formatted connection string |
Source code in oper8/x/datastores/redis/connection.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
|
get_tls_cert()
Get the current TLS certificate for a client connection if TLS is enabled
If TLS is enabled, but the cert is not found, this function will raise an AssertionError
Returns:
Name | Type | Description |
---|---|---|
tls_cert |
Optional[str]
|
str or None PEM encoded cert string (not base64-encoded) if found, otherwise None |
Source code in oper8/x/datastores/redis/connection.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|
to_dict()
Return the dict representation of the object for the CR
Source code in oper8/x/datastores/redis/connection.py
152 153 154 |
|
factory
Redis instance factory
RedisFactory
Bases: DatastoreSingletonFactoryBase
The common factory that will manage instances of Redis
Source code in oper8/x/datastores/redis/factory.py
10 11 12 13 14 |
|
interfaces
Base class interface for a Redis component
IRedisComponent
Bases: Datastore
A redis chart provides access to a redis instance
Source code in oper8/x/datastores/redis/interfaces.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|
get_connection()
Get the connection object for this instance
Source code in oper8/x/datastores/redis/interfaces.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
oper8x_component
This class provides a base class with shared functionality that all concrete components can use.
Oper8xComponent
Bases: Component
The Oper8xComponent provides common config-based utilities on top of the core oper8.Component base class. It can be used as a drop-in replacement.
Source code in oper8/x/oper8x_component.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
|
__init__(session, disabled=False)
Construct with a member to access the session in implementations
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The session for the current deployment |
required |
disabled
|
bool
|
bool Whether or not this component is disabled in the current configuration |
False
|
Source code in oper8/x/oper8x_component.py
28 29 30 31 32 33 34 35 36 37 38 39 |
|
deploy(session)
Override the base Component's implementation of deploy to insert the dependency hash annotation. See NOTE in deps_annotation for explanation of why deploy is used instead of update_object_definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The session for the current deployment |
required |
Returns:
Name | Type | Description |
---|---|---|
success |
bool
|
bool True on successful application of the resource to the cluster |
Source code in oper8/x/oper8x_component.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
get_cluster_name(resource_name)
Get the name for a given resource with any instance scoping applied
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource_name
|
str
|
str The unscoped name of a kubernetes resource |
required |
Returns:
Name | Type | Description |
---|---|---|
resource_cluster_name |
str
|
str The name that the resource will use in the cluster |
Source code in oper8/x/oper8x_component.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
get_replicas(force=False)
Get the replica count for this component based on the current deploy's t-shirt size and the state of the instance-size label. A replica count is only returned if there is not an existing replica count in the cluster for this deployment, the t-shirt size has changed, or the force flag is True.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
force
|
bool
|
bool If True, the state of the cluster will not be checked |
False
|
Returns:
Name | Type | Description |
---|---|---|
replicas |
Union[int, None]
|
Union[int, None] If replicas should be set for this deployment, the integer count will be returned, otherwise None is returned. |
Source code in oper8/x/oper8x_component.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
|
update_object_definition(session, internal_name, resource_definition)
For components assigned to different namespaces, ensure that the target namespace is set
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The session for this deploy |
required |
internal_name
|
str
|
str The internal name of the object to update |
required |
resource_definition
|
dict
|
dict The dict representation of the resource to modify |
required |
Returns:
Name | Type | Description |
---|---|---|
resource_definition |
dict
|
dict The dict representation of the resource with any modifications applied |
Source code in oper8/x/oper8x_component.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
utils
Common utilities for reused components
abc_static
This module adds metaclass support for declaring an interface with @abstractmethod methods that MUST be implemented as @classmethod or @staticmethod
ABCStatic
An ABCStatic class is a child of abc.ABC which has support for enforcing methods which combine @classmethod and @abstractmethod
Source code in oper8/x/utils/abc_static.py
68 69 70 71 |
|
ABCStaticMeta
Bases: ABCMeta
The StaticABCMeta class is a metaclass that enforces implementations of base class functions marked as both @abstractmethod and @classmethod. Methods with this signature MUST be implemented with the @classmethod or @staticmethod decorator in derived classes.
Source code in oper8/x/utils/abc_static.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
common
Shared utilities accessible to all components
from_string_or_number(value)
Handle strings or numbers for fields that can be either string or numeric
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Union[int, str, float]
|
Union[str, int, float] Quantity type that can be in numeric or string form (e.g. resources) |
required |
Returns:
Name | Type | Description |
---|---|---|
formatted_value |
Union[int, str, float]
|
Union[str, int, float] The value formatted as the correct type |
Source code in oper8/x/utils/common.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
|
get_deploy_labels(session, base_labels=None)
Get labels for a Deployment resource on top of the standard base labels
Source code in oper8/x/utils/common.py
182 183 184 185 186 187 |
|
get_labels(cluster_name, session, component_name=None)
Common utility for fetching the set of metadata.labels for a given resource. Args: cluster_name: str The name of the resource as it will be applied to the cluster including any scoping applied by get_resource_cluster_name session: DeploySession The session for the current deployment component_name: str The name of the component that manages this resource. NOTE: This argument is optional for backwards compatibility, but should always be provided to ensure accurate labels! Returns: labels: Dict[str, str] The full set of labels to use for the given resource
Source code in oper8/x/utils/common.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
get_replicas(session, component_name, unscoped_name, force=False, replicas_override=None)
Get the replica count for the given resource.
This function consolidates logic for getting replicas for all components in the application. It allows replicas to be conditionally set only when needed to avoid thrashing with HPAs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The current deploy session |
required |
component_name
|
str
|
str The name of the component to get replicas for |
required |
unscoped_name
|
str
|
str The external name of the deployment without scoping |
required |
force
|
bool
|
bool If True, the state of the cluster will not be checked |
False
|
replicas_override
|
Union[int, None]
|
int or None An override value to use in place of the normal config-based value |
None
|
Returns:
Name | Type | Description |
---|---|---|
replicas |
Union[int, None]
|
int or None If replicas should not be set for this resource, None is returned, otherwise the number of replicas is returned based on the t-shirt size for the instance. |
Source code in oper8/x/utils/common.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
get_resource_cluster_name(resource_name, component, session)
Common helper function to get the name a given kubernetes resource should use when deployed to the cluster.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource_name
|
str
|
str The raw name for the resource (e.g. sireg-secret) |
required |
component
|
Component
|
Union[Component, str] The component (or component name) that owns this resource |
required |
session
|
Session
|
Session The session for the current reconciliation deploy |
required |
Returns:
Name | Type | Description |
---|---|---|
resource_cluster_name |
str The resource name with appropriate scoping and truncation added |
Source code in oper8/x/utils/common.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
get_slot_name(component, session)
Get the slot name for the given component in the current deployment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
component
|
Union[Component, str]
|
Union[Component, str] The component to fetch the slot name for |
required |
session
|
Session
|
DeploySession The session for the current deployment |
required |
Returns:
Name | Type | Description |
---|---|---|
slot_name |
str
|
str The string name of the slot where the given component will live for this deployment. For global components, the static global slot name is returned |
Source code in oper8/x/utils/common.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
|
is_global(component, session)
Determine if the given component is global in this deployment
Parameters:
Name | Type | Description | Default |
---|---|---|---|
component
|
Union[Component, str]
|
Union[Component, str] The component to fetch the slot name for |
required |
session
|
Session
|
Session The session for the current deployment |
required |
Returns:
Name | Type | Description |
---|---|---|
is_global |
bool
|
bool True if the given component is global! |
Source code in oper8/x/utils/common.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
|
metadata_defaults(cluster_name, session, **kwargs)
This function will create the metadata object given the external name for a resource. The external name should be created using common.get_resource_external_name. These functions are separate because the external name is often needed independently, so it will be pre-computed at the start of most components.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cluster_name
|
str
|
str The fully scoped and truncated name that the resource will use in the cluster (metadata.name) |
required |
session
|
Session
|
DeploySession The session for the current reconciliation deploy |
required |
Returns:
Name | Type | Description |
---|---|---|
metadata |
dict
|
dict The constructed metadata dict |
Source code in oper8/x/utils/common.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
|
mount_mode(octal_val)
This helper gets the decimal version of an octal representation of file permissions used for a volume mount.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
octal_val
|
int or str The number as octal (e.g. 755 or "0755") |
required |
Returns:
Name | Type | Description |
---|---|---|
decimal_val |
int The decimal integer value corresponding to the given octal value which can be used in VolumeMount's default_mode field |
Source code in oper8/x/utils/common.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
|
constants
Shared constants across the various oper8.x tools
deps_annotation
This module holds shared functionality for adding dependency annotations to all resources that need them.
A dependency annotation on a Pod encodes a unique hash of the set of data-resources that the Pod depends on. For example, if a Pod mounds a Secret and a ConfigMap, the dependency annotation will hold a unique hash of the data content of these secrets. The role of the dependency annotation is to force a rollover when upstream data-resources change their content so that the content is guaranteed to be picked up by the consuming Pod.
add_deps_annotation(component, session, resource_definition)
Add the dependency hash annotation to any pods found in the given object
Parameters:
Name | Type | Description | Default |
---|---|---|---|
component
|
Component
|
Component The component that this resource belongs to |
required |
session
|
Session
|
Session The session for this deploy |
required |
resource_definition
|
dict
|
dict The dict representation of the resource to modify |
required |
Returns:
Name | Type | Description |
---|---|---|
resource_definition |
dict
|
dict The dict representation of the resource with any modifications applied |
Source code in oper8/x/utils/deps_annotation.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
get_deps_annotation(session, dependencies, resource_name='', namespace=_SESSION_NAMESPACE)
Get a dict holding an annotation key/value pair representing the unique content hash of all given dependencies. This can be used to force pods to roll over when a dependency such as a ConfigMap or Secret changes its content. This function supports two ways of fetching dependency content:
- Dict representation of the object
- Tuple of the scoped (kind, name) for the object
Additionally, this function holds special logic for ConfigMap and Secret dependencies, but can handle arbitrary kinds. For kinds without special logic, the full dict representation is used to compute the hash.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The current session |
required |
dependencies
|
List[Union[dict, Tuple[str, str]]]
|
list(dict or str or cdk8s.ApiObject) An ordered list of dependencies to compute the content hash from |
required |
resource_name
|
str
|
str A string name for the resource (used for logging) |
''
|
namespace
|
Optional[str]
|
Optional[str] Namespace where the dependencies live. Defaults to session.namespace |
_SESSION_NAMESPACE
|
Returns:
Name | Type | Description |
---|---|---|
deps_annotation |
dict
|
dict A dict representation of the key/value pair used to hold the content hash for the given set of dependencies |
Source code in oper8/x/utils/deps_annotation.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
tls
Shared utilities for managing TLS keys and certs
generate_ca_cert(key, encode=True)
Generate a Certificate Authority certificate based on a private key
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
RSAPrivateKey The private key that will pair with this CA cert |
required | |
encode
|
bool Base64 encode the output pem bytes |
True
|
Returns:
Name | Type | Description |
---|---|---|
ca |
str The PEM encoded string for this CA cert |
Source code in oper8/x/utils/tls.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
generate_derived_key_cert_pair(ca_key, san_list, encode=True, key_cert_sign=False)
Generate a certificate for use in encrypting TLS traffic, derived from a common key
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
RSAPrivateKey The private key that will pair with this CA cert |
required | |
san_list
|
list(str) List of strings to use for the Subject Alternate Name |
required | |
encode
|
bool Whether or not to base64 encode the output pem strings |
True
|
|
key_cert_sign
|
bool Whether or not to set the key_cert_sign usage bit in the generated certificate. This may be needed when the derived key/cert will be used as an intermediate CA or expected to act as a self-signed CA. Reference: https://ldapwiki.com/wiki/KeyUsage |
False
|
Returns:
Name | Type | Description |
---|---|---|
key_pem |
str The pem-encoded key (base64 encoded if encode set) |
|
crt_pem |
str The pem-encoded cert (base64 encoded if encode set) |
Source code in oper8/x/utils/tls.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
|
generate_key(encode=True)
Generate a new RSA key for use when generating TLS components
Parameters:
Name | Type | Description | Default |
---|---|---|---|
encode
|
bool Base64 encode the output pem bytes |
True
|
Returns:
Name | Type | Description |
---|---|---|
key |
RSAPrivateKey The key object that can be used to sign certificates |
|
key_pem |
str The PEM encoded string for the key |
Source code in oper8/x/utils/tls.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
get_subject(common_name=DEFAULT_COMMON_NAME)
Get the subject object used when creating self-signed certificates. This will be consistent across all components, but will be tailored to the domain of the cluster.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
common_name
|
str
|
str The Common Name to use for this subject |
DEFAULT_COMMON_NAME
|
Returns:
Name | Type | Description |
---|---|---|
subject |
Name
|
x509.Name The full subect object to use when constructing certificates |
Source code in oper8/x/utils/tls.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
parse_private_key_pem(key_pem)
Parse the content of a pem-encoded private key file into an RSAPrivateKey
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key_pem
|
str The pem-encoded key (not base64 encoded) |
required |
Returns:
Name | Type | Description |
---|---|---|
key |
RSAPrivateKey The parsed key object which can be used for signing certs |
Source code in oper8/x/utils/tls.py
212 213 214 215 216 217 218 219 220 221 222 223 |
|
parse_public_key_pem_from_cert(cert_pem)
Extract the pem-encoded public key from a pem-encoded
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cert_pem
|
str The pem-encoded certificate (not base64 encoded) |
required |
Returns:
Name | Type | Description |
---|---|---|
key |
RSAPrivateKey The parsed key object which can be used for signing certs |
Source code in oper8/x/utils/tls.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
|
tls_context
Common tls_context module setup
factory
This module implements a factory for TlsContext implementations
get_tls_context(session, config_overrides=None)
Get an instance of the configured implementation of the tls context
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The current deploy session |
required |
config_overrides
|
Optional[dict]
|
Optional[dict] Optional runtime config values. These will overwrite any values pulled from the session.config |
None
|
Returns:
Name | Type | Description |
---|---|---|
tls_context |
ITlsContext
|
ITlsContext The constructed instance of the context |
Source code in oper8/x/utils/tls_context/factory.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
register_tls_context_type(context_class)
Register a constructor for a given context implementation type
Parameters:
Name | Type | Description | Default |
---|---|---|---|
context_class
|
Type[ITlsContext]
|
Type[ITlsContext] The ITlsContext child class to register |
required |
Source code in oper8/x/utils/tls_context/factory.py
45 46 47 48 49 50 51 52 |
|
interface
This module defines the interface needed to provide TLS key/cert pairs to a given microservice and fetch a client-side certificate for making calls to a microservice that serves a key/cert pair derived from this context.
ITlsContext
Bases: ABC
This interface encapsulates the management of TLS for a running instance of the operand. It encapsulates the following functions:
- Manage a CA key/cert pair for signing derived microservice certificates
- Create derived key/cert pairs for individual microservices
Source code in oper8/x/utils/tls_context/interface.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
__init__(session, config)
Construct with the current session so that member functions do not take it as an argument
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The current deploy session |
required |
config
|
Config
|
aconfig.Config The config for this instance |
required |
Source code in oper8/x/utils/tls_context/interface.py
32 33 34 35 36 37 38 39 40 41 42 43 |
|
get_client_cert(client_component, encode=True)
abstractmethod
Get a cert which can be used by a client to connect to a server which is serving using a key/cert pair signed by the shared CA.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client_component
|
Component
|
Component The Component that manages the client. This can be used to add a new Component if needed that will manage the resource for the derived content and configure dependencies. |
required |
encode
|
bool
|
bool Whether or not to base64 encode the output pem strings |
True
|
Returns:
Name | Type | Description |
---|---|---|
crt_pem |
str
|
Optional[str] The pem-encoded cert (base64 encoded if encode set). |
Source code in oper8/x/utils/tls_context/interface.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
|
get_server_key_cert_pair(server_component, key_name=None, encode=True, existing_key_pem=None, existing_cert_pem=None)
abstractmethod
Get the PEM encoded value of the key/cert pair for a given server. You have to forst request_server_key_cert_pair in render_config phase, and later in render_chart retrieve generated cert.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
server_component
|
Component
|
Component The Component that manages the server. This can be used to add a new Component if needed that will manage the resource for the derived content and configure dependencies. |
required |
key_name
|
str
|
str In case component requires multiple certificates. The key_name is used to distinguies between component cert requests. |
None
|
encode
|
bool
|
bool Whether or not to base64 encode the output pem strings |
True
|
existing_key_pem
|
str
|
str Optionaly, you may provide the (decoded) value of PK/CERK pair. TLS context is free to check the Cert/PK and return this pair or generate new one. |
None
|
existing_cert_pem
|
str
|
str, Optionaly, you may provide the (decoded) value of PK/CERK pair. TLS context is free to check the Cert/PK and return this pair or generate new one. |
None
|
Returns: key_pem: Optional[str] This is the pem-encoded key content (base64 encoded if encode is set) cert_pem: Optional[str] This is the pem-encoded cert content (base64 encoded if encode is set)
Source code in oper8/x/utils/tls_context/interface.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
request_server_key_cert_pair(server_component, san_hostnames_list, san_ip_list=None, key_name=None, intermediate_ca=False)
Request creation of the PEM encoded value of the key/cert pair for a given server. This function has to be called from before render_chart is called. I.e., parse_config / Component constructor phase. Implementations of this function will generate the pair (in background) if it has not been already requested.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
server_component
|
Component
|
Component The Component that manages the server. This can be used to add a new Component if needed that will manage the resource for the derived content and configure dependencies. |
required |
san_hostnames_list
|
List[str]
|
List[str] The list of Subject Alternate Names (hostnames only) |
required |
san_ip_list
|
List[str]
|
List[str] The list of Subject Alternate Names (ip addresses only, IPv4, IPv6) |
None
|
key_name
|
str
|
str In case component requires multiple certificates. The key_name is used to distinguishes between component cert requests. |
None
|
intermediate_ca
|
bool
|
bool Whether or not to configure the certificate for use as an intermediate CA. This implies setting the key_cert_sign usage bit in the generated cert. Reference: https://ldapwiki.com/wiki/KeyUsage |
False
|
Source code in oper8/x/utils/tls_context/interface.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
internal
This implementation of the ITlsContext uses internal code to manage the tls context
InternalCaComponent
Bases: Oper8xComponent
This Component will manage a single secret containing a CA key/cert pair
Source code in oper8/x/utils/tls_context/internal.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
|
__init__(session, *args, labels=None, **kwargs)
Construct the parent Component and set up internal data holders
Source code in oper8/x/utils/tls_context/internal.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
build_chart(*args, **kwargs)
Implement delayed chart construction in build_chart
Source code in oper8/x/utils/tls_context/internal.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|
get_ca_key_cert()
Get the pem-encoded CA key cert pair
Returns:
Name | Type | Description |
---|---|---|
ca_key_pem |
str
|
str The pem-encoded (not base64 encoded) secret key |
ca_crt_pem |
str
|
str The pem-encoded (not base64 encoded) secret cert |
Source code in oper8/x/utils/tls_context/internal.py
260 261 262 263 264 265 266 267 268 269 270 |
|
InternalTlsContext
Bases: ITlsContext
Source code in oper8/x/utils/tls_context/internal.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
__init__(session, *args, **kwargs)
At construct time, this instance will add a Component to the session which will manage the CA secret
Source code in oper8/x/utils/tls_context/internal.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
get_client_cert(client_component, encode=True)
Get the CA's public cert
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client_component
|
Component
|
Component The Component that manages the client. This implementation does not need the component. |
required |
encode
|
bool
|
bool Whether or not to base64 encode the output pem strings |
True
|
Returns:
Name | Type | Description |
---|---|---|
crt_pem |
str
|
Optional[str] The pem-encoded cert (base64 encoded if encode set) |
Source code in oper8/x/utils/tls_context/internal.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
get_server_key_cert_pair(server_component, key_name=None, encode=True, existing_key_pem=None, existing_cert_pem=None)
This function derives a server key/cert pair from the CA key/cert managed by the internal component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
server_component
|
Component
|
Component The Component that manages the server. This can be used to add a new Component if needed that will manage the resource for the derived content and configure dependencies. |
required |
key_name
|
str
|
str In case component requires multiple certificates. The key_name is used to distinguish between component cert requests. |
None
|
encode
|
bool
|
bool Whether or not to base64 encode the output pem strings |
True
|
existing_key_pem
|
str
|
str If both existing key/cert are specified, then they are returned immediately without any checks |
None
|
existing_cert_pem
|
str
|
str If both existing key/cert are specified, then they are returned immediately without any checks |
None
|
Returns: key_pem: str This is the pem-encoded key content (base64 encoded if encode is set) cert_pem: str This is the pem-encoded cert content (base64 encoded if encode is set)
Source code in oper8/x/utils/tls_context/internal.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
request_server_key_cert_pair(server_component, san_hostnames_list, san_ip_list=None, key_name=None, intermediate_ca=False)
Request creation of the PEM encoded value of the key/cert pair for a given server. This function has to be called from before render_chart is called. I.e., parse_config / Component constructor phase. Implementations of this function will generate the pair (in background) if it has not been already requested.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
server_component
|
Component
|
Component The Component that manages the server. This can be used to add a new Component if needed that will manage the resource for the derived content and configure dependencies. |
required |
san_list
|
List[str] The list of Subject Alternate Names |
required | |
key_name
|
str
|
str In case component requires multiple certificates. The key_name is used to distinguish between component cert requests. |
None
|
intermediate_ca
|
bool
|
bool Whether or not to configure the certificate for use as an intermediate CA. This implies setting the key_cert_sign usage bit in the generated cert. Reference: https://ldapwiki.com/wiki/KeyUsage |
False
|
Source code in oper8/x/utils/tls_context/internal.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
public
This file holds functions that should be used outside of this module by components, subsystems, and applications that need access to the TLS context functionality.
get_client_cert(session, *args, **kwargs)
Get the CA's public cert
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The current deploy session |
required |
Passthrough Args
See ITlsContext.get_client_cert
Returns:
Name | Type | Description |
---|---|---|
crt_pem |
str
|
Optional[str] The pem-encoded cert (base64 encoded if encode set), |
Source code in oper8/x/utils/tls_context/public.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
get_server_key_cert_pair(session, *args, **kwargs)
Get the previously requested PEM encoded value of the key/cert pair for a given server. Implementations will retrieveh the pair if it does not exist and will fetch its content if it does. If the content is not available, the assertion is triggered.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The current deploy session |
required |
Passthrough Args
See ITlsContext.get_server_key_cert_pair
Returns:
Name | Type | Description |
---|---|---|
key_pem |
str
|
str This is the pem-encoded key content (base64 encoded if encode is set) |
cert_pem |
str
|
str This is the pem-encoded cert content (base64 encoded if encode is set) |
Source code in oper8/x/utils/tls_context/public.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
request_server_key_cert_pair(session, *args, **kwargs)
Request creation of the PEM encoded value of the key/cert pair for a given server. This function has to be called from before render_chart is called. I.e., parse_config / Component constructor phase. Implementations of this function will generate the pair (in background) if it has not been already requested.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
Session
|
Session The current deploy session |
required |
Passthrough Args
See ITlsContext.request_server_key_cert_pair
Source code in oper8/x/utils/tls_context/public.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|