-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
283 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
# Copyright (c) 2024 Canonical Ltd. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
# implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
from typing import Any | ||
|
||
from sunbeam.clusterd.client import Client | ||
from sunbeam.jobs.juju import JujuHelper | ||
from sunbeam.jobs.steps import ( | ||
AddMachineUnitsStep, | ||
DeployMachineApplicationStep, | ||
RemoveMachineUnitStep, | ||
) | ||
|
||
from anvil.jobs.manifest import Manifest | ||
|
||
APPLICATION = "virtual_ip" | ||
CONFIG_KEY = "TerraformVarsVirtualIPPlan" | ||
VIRTUALIP_APP_TIMEOUT = ( | ||
180 # 3 minutes, managing the application should be fast | ||
) | ||
VIRTUALIP_UNIT_TIMEOUT = ( | ||
1200 # 15 minutes, adding / removing units can take a long time | ||
) | ||
|
||
|
||
class DeployVirtualIpApplicationStep(DeployMachineApplicationStep): | ||
"""Deploy VirtualIp application using Terraform""" | ||
|
||
def __init__( | ||
self, | ||
client: Client, | ||
manifest: Manifest, | ||
jhelper: JujuHelper, | ||
model: str, | ||
refresh: bool = False, | ||
): | ||
super().__init__( | ||
client, | ||
manifest, | ||
jhelper, | ||
CONFIG_KEY, | ||
APPLICATION, | ||
model, | ||
"virtual-ip-plan", | ||
"Deploy VirtualIp", | ||
"Deploying VirtualIp", | ||
refresh, | ||
) | ||
|
||
def get_application_timeout(self) -> int: | ||
return VIRTUALIP_APP_TIMEOUT | ||
|
||
def extra_tfvars(self) -> dict[str, Any]: | ||
# TODO: How do we pass the VIP from command line to here? | ||
if virtual_ip := None: | ||
return {"virtual_ip": virtual_ip} | ||
return {} | ||
|
||
|
||
class AddVirtualIpUnitsStep(AddMachineUnitsStep): | ||
"""Add VirtualIp Unit.""" | ||
|
||
def __init__( | ||
self, | ||
client: Client, | ||
names: list[str] | str, | ||
jhelper: JujuHelper, | ||
model: str, | ||
): | ||
super().__init__( | ||
client, | ||
names, | ||
jhelper, | ||
CONFIG_KEY, | ||
APPLICATION, | ||
model, | ||
"Add VirtualIp unit", | ||
"Adding VirtualIp unit to machine", | ||
) | ||
|
||
def get_unit_timeout(self) -> int: | ||
return VIRTUALIP_UNIT_TIMEOUT | ||
|
||
|
||
class RemoveVirtualIpUnitStep(RemoveMachineUnitStep): | ||
"""Remove VirtualIp Unit.""" | ||
|
||
def __init__( | ||
self, client: Client, name: str, jhelper: JujuHelper, model: str | ||
): | ||
super().__init__( | ||
client, | ||
name, | ||
jhelper, | ||
CONFIG_KEY, | ||
APPLICATION, | ||
model, | ||
"Remove VirtualIp unit", | ||
"Removing VirtualIp unit from machine", | ||
) | ||
|
||
def get_unit_timeout(self) -> int: | ||
return VIRTUALIP_UNIT_TIMEOUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Copyright (c) 2024 Canonical Ltd. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
# implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
terraform { | ||
|
||
required_providers { | ||
juju = { | ||
source = "juju/juju" | ||
version = "= 0.11.0" | ||
} | ||
} | ||
|
||
} | ||
|
||
provider "juju" {} | ||
|
||
data "juju_model" "machine_model" { | ||
name = var.machine_model | ||
} | ||
|
||
resource "juju_application" "keepalived" { | ||
name = "keepalived" | ||
model = data.juju_model.machine_model.name | ||
units = 1 | ||
|
||
charm { | ||
name = "keepalived" | ||
channel = var.charm_keepalived_channel | ||
revision = var.charm_keepalived_revision | ||
base = "ubuntu@22.04" | ||
} | ||
|
||
config = var.charm_keepalived_config | ||
} | ||
|
||
resource "juju_relation" "haprox_keepalived" { | ||
provider = data.juju_application.haproxy.name | ||
requirer = data.juju_application.keepalived.name | ||
} | ||
|
||
resource "juju_config" "keepalived" { | ||
# do nothing if the vip is not given | ||
count = var.virtual_ip != "" ? 1 : 0 | ||
application = data.juju_application.keepalived.name | ||
model = data.juju_model.machine_model.name | ||
|
||
config = { | ||
virtual_ip = var.virtual_ip | ||
} | ||
} |
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,49 @@ | ||
# Copyright (c) 2024 Canonical Ltd. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
# implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
variable "charm_keepalived_channel" { | ||
description = "Operator channel for Virtual Ip deployment" | ||
type = string | ||
default = "14/stable" | ||
} | ||
|
||
variable "charm_keepalived_revision" { | ||
description = "Operator channel revision for Virtual Ip deployment" | ||
type = number | ||
default = null | ||
} | ||
|
||
variable "charm_keepalived_config" { | ||
description = "Operator config for Virtual Ip deployment" | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
variable "machine_ids" { | ||
description = "List of machine ids to include" | ||
type = list(string) | ||
default = [] | ||
} | ||
|
||
variable "machine_model" { | ||
description = "Model to deploy to" | ||
type = string | ||
} | ||
|
||
variable "virtual_ip" { | ||
description = "The virtual IP address for keepalived" | ||
type = string | ||
default = "" | ||
} |