-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add warning if ingress is not established
- Loading branch information
1 parent
0d0071f
commit d406758
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import dataclasses | ||
import logging | ||
from typing import Optional | ||
|
||
from charmed_kubeflow_chisme.components import Component | ||
from ops import ActiveStatus, BlockedStatus, StatusBase | ||
|
||
|
||
@dataclasses.dataclass | ||
class IngressRelationWarnIfMissingInputs: | ||
"""Defines the required inputs for IngressRelationWarnIfMissing.""" | ||
|
||
interface: Optional[dict] | ||
|
||
|
||
class IngressRelationWarnIfMissing(Component): | ||
"""Component that logs a warning if we have no Ingress relation established.""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
"""Component that logs a warning if we have no Ingress relation established.""" | ||
super().__init__(*args, **kwargs) | ||
# Attach a logger. Use this instead of the global one to make mocking easier | ||
self.logger = logging.getLogger(__name__) | ||
|
||
def get_status(self) -> StatusBase: | ||
"""Always Active unless it cannot get inputs.""" | ||
try: | ||
inputs = self._inputs_getter() | ||
if not inputs.interface: | ||
self.logger.warning( | ||
"No ingress relation established. To be used by KFP in Charmed Kubeflow, this" | ||
" charm requires an Ingress relation." | ||
) | ||
return ActiveStatus("Active but no ingress relation established") | ||
|
||
return ActiveStatus() | ||
except Exception as e: | ||
self.logger.error(f"Error getting inputs for IngressRelationWarnIfMissing: {e}") | ||
return BlockedStatus("Error getting inputs. See logs") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters