Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Pod to PersistentVolume relationship #15023

Merged
merged 2 commits into from
Sep 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/models/container_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class ContainerGroup < ApplicationRecord
belongs_to :old_container_project, :foreign_key => "old_container_project_id", :class_name => 'ContainerProject'
belongs_to :container_build_pod
has_many :container_volumes, :as => :parent, :dependent => :destroy
has_many :persistent_volume_claim, :through => :container_volumes
has_many :persistent_volumes, -> { where(:type=>'PersistentVolume') }, :through => :persistent_volume_claim, :source => :container_volumes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this our :type or is it the type over in :persisted_volume_claim?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a test for claim?

Copy link
Contributor Author

@nimrodshn nimrodshn May 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this our :type or is it the type over in :persisted_volume_claim?

@kbrock what do you mean by "our :type" vs "type over in :persistent_volume_claim?
Will add a test 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kbrock added tests for pvc relationship.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need the where? I don't see any descendants of PersistentVolume


# Metrics destroy is handled by purger
has_many :metrics, :as => :resource
Expand Down
51 changes: 51 additions & 0 deletions spec/models/container_group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
describe ContainerGroup do
it "has container volumes and pods" do
pvc = FactoryGirl.create(
:persistent_volume_claim,
:name => "test_claim"
)

group = FactoryGirl.create(
:container_group,
:name => "group",
)

ems = FactoryGirl.create(
:ems_kubernetes,
:id => group.id,
:name => "ems"
)

FactoryGirl.create(
:container_volume,
:name => "container_volume",
:type => 'ContainerVolume',
:parent => group,
:persistent_volume_claim => pvc
)

FactoryGirl.create(
:persistent_volume,
:name => "persistent_volume0",
:parent => ems,
:persistent_volume_claim => pvc
)

FactoryGirl.create(
:persistent_volume,
:name => "persistent_volume1",
:parent => ems,
:persistent_volume_claim => pvc
)

assert_pod_to_pv_relationships(group)
end

def assert_pod_to_pv_relationships(group)
expect(group.persistent_volume_claim.first.name).to eq("test_claim")
expect(group.persistent_volume_claim.count).to eq(1)
expect(group.persistent_volumes.first.name).to eq("persistent_volume0")
expect(group.persistent_volumes.second.name).to eq("persistent_volume1")
expect(group.persistent_volumes.count).to eq(2)
end
end