mirror of
https://github.com/ansible/awx.git
synced 2026-03-24 12:25:01 -02:30
Merge pull request #9584 from shanemcd/explicit-is_container_group
Explicit db field for is_container_group Reviewed-by: Jake McDermott <yo@jakemcdermott.me> Reviewed-by: Ryan Petrello <None>
This commit is contained in:
@@ -17,13 +17,14 @@ class InstanceNotFound(Exception):
|
||||
|
||||
|
||||
class RegisterQueue:
|
||||
def __init__(self, queuename, controller, instance_percent, inst_min, hostname_list):
|
||||
def __init__(self, queuename, controller, instance_percent, inst_min, hostname_list, is_container_group=None):
|
||||
self.instance_not_found_err = None
|
||||
self.queuename = queuename
|
||||
self.controller = controller
|
||||
self.instance_percent = instance_percent
|
||||
self.instance_min = inst_min
|
||||
self.hostname_list = hostname_list
|
||||
self.is_container_group = is_container_group
|
||||
|
||||
def get_create_update_instance_group(self):
|
||||
created = False
|
||||
@@ -36,6 +37,10 @@ class RegisterQueue:
|
||||
ig.policy_instance_minimum = self.instance_min
|
||||
changed = True
|
||||
|
||||
if self.is_container_group:
|
||||
ig.is_container_group = self.is_container_group
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
ig.save()
|
||||
|
||||
|
||||
@@ -144,7 +144,8 @@ class InstanceManager(models.Manager):
|
||||
from awx.main.management.commands.register_queue import RegisterQueue
|
||||
pod_ip = os.environ.get('MY_POD_IP')
|
||||
registered = self.register(ip_address=pod_ip)
|
||||
RegisterQueue('tower', None, 100, 0, []).register()
|
||||
is_container_group = settings.IS_K8S
|
||||
RegisterQueue('tower', None, 100, 0, [], is_container_group).register()
|
||||
return registered
|
||||
else:
|
||||
return (False, self.me())
|
||||
|
||||
27
awx/main/migrations/0132_instancegroup_is_container_group.py
Normal file
27
awx/main/migrations/0132_instancegroup_is_container_group.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# Generated by Django 2.2.16 on 2021-03-13 14:53
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def migrate_existing_container_groups(apps, schema_editor):
|
||||
InstanceGroup = apps.get_model('main', 'InstanceGroup')
|
||||
|
||||
for group in InstanceGroup.objects.filter(credential__isnull=False).iterator():
|
||||
group.is_container_group = True
|
||||
group.save(update_fields=['is_container_group'])
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('main', '0131_undo_org_polymorphic_ee'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='instancegroup',
|
||||
name='is_container_group',
|
||||
field=models.BooleanField(default=False),
|
||||
),
|
||||
migrations.RunPython(migrate_existing_container_groups, migrations.RunPython.noop),
|
||||
]
|
||||
@@ -199,6 +199,9 @@ class InstanceGroup(HasPolicyEditsMixin, BaseModel, RelatedJobsMixin):
|
||||
null=True,
|
||||
on_delete=models.CASCADE
|
||||
)
|
||||
is_container_group = models.BooleanField(
|
||||
default=False
|
||||
)
|
||||
credential = models.ForeignKey(
|
||||
'Credential',
|
||||
related_name='%(class)ss',
|
||||
@@ -253,13 +256,6 @@ class InstanceGroup(HasPolicyEditsMixin, BaseModel, RelatedJobsMixin):
|
||||
def is_isolated(self):
|
||||
return bool(self.controller)
|
||||
|
||||
@property
|
||||
def is_container_group(self):
|
||||
if settings.IS_K8S:
|
||||
return True
|
||||
|
||||
return bool(self.credential and self.credential.kubernetes)
|
||||
|
||||
'''
|
||||
RelatedJobsMixin
|
||||
'''
|
||||
|
||||
@@ -49,6 +49,7 @@ def isolated_instance_group(instance_group, instance):
|
||||
def containerized_instance_group(instance_group, kube_credential):
|
||||
ig = InstanceGroup(name="container")
|
||||
ig.credential = kube_credential
|
||||
ig.is_container_group = True
|
||||
ig.save()
|
||||
return ig
|
||||
|
||||
@@ -287,6 +288,7 @@ def test_containerized_group_default_fields(instance_group, kube_credential):
|
||||
assert ig.policy_instance_minimum == 5
|
||||
assert ig.policy_instance_percentage == 5
|
||||
ig.credential = kube_credential
|
||||
ig.is_container_group = True
|
||||
ig.save()
|
||||
assert ig.policy_instance_list == []
|
||||
assert ig.policy_instance_minimum == 0
|
||||
|
||||
@@ -13,6 +13,7 @@ from awx.main.utils import (
|
||||
@pytest.fixture
|
||||
def containerized_job(default_instance_group, kube_credential, job_template_factory):
|
||||
default_instance_group.credential = kube_credential
|
||||
default_instance_group.is_container_group = True
|
||||
default_instance_group.save()
|
||||
objects = job_template_factory('jt', organization='org1', project='proj',
|
||||
inventory='inv', credential='cred',
|
||||
|
||||
Reference in New Issue
Block a user