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
Fix service volume update #1742
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ def validate | |
if self.links | ||
validate_links(self.grid_service.grid, self.grid_service.stack, self.links) | ||
end | ||
|
||
if self.strategy && !self.strategies[self.strategy] | ||
add_error(:strategy, :invalid_strategy, 'Strategy not supported') | ||
end | ||
|
@@ -28,6 +27,17 @@ def validate | |
if self.secrets | ||
validate_secrets_exist(self.grid_service.grid, self.secrets) | ||
end | ||
if self.grid_service.stateful? | ||
if self.volumes_from && self.volumes_from.size > 0 | ||
add_error(:volumes_from, :invalid, 'Cannot combine stateful & volumes_from') | ||
end | ||
if self.volumes | ||
changed_volumes = self.volumes.select { |v| !self.grid_service.volumes.include?(v) } | ||
if changed_volumes.any? { |v| !v.include?(':') } | ||
add_error(:volumes, :invalid, 'Adding a non-named volume is not supported to a stateful service') | ||
end | ||
end | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't these be also updated in the create mutation to have same "rules" in both create and update? This basically means that it should be separate method in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like the existing
|
||
end | ||
|
||
def execute | ||
|
@@ -53,6 +63,8 @@ def execute | |
attributes[:devices] = self.devices if self.devices | ||
attributes[:deploy_opts] = self.deploy_opts if self.deploy_opts | ||
attributes[:health_check] = self.health_check if self.health_check | ||
attributes[:volumes] = self.volumes if self.volumes | ||
attributes[:volumes_from] = self.volumes_from if self.volumes_from | ||
|
||
if self.links | ||
attributes[:grid_service_links] = build_grid_service_links( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,111 @@ | |
).run | ||
expect(outcome.success?).to be(true) | ||
end | ||
|
||
context 'volumes' do | ||
context 'stateless service' do | ||
it 'allows to add non-named volume' do | ||
outcome = described_class.new( | ||
grid_service: redis_service, | ||
volumes: ['/foo'] | ||
).run | ||
expect(outcome.success?).to be_truthy | ||
expect(outcome.result.volumes).to eq(['/foo']) | ||
end | ||
|
||
it 'allows to add named volume' do | ||
outcome = described_class.new( | ||
grid_service: redis_service, | ||
volumes: ['foo:/foo'] | ||
).run | ||
expect(outcome.success?).to be_truthy | ||
expect(outcome.result.volumes).to eq(['foo:/foo']) | ||
end | ||
|
||
it 'allows to add bind mounted volume' do | ||
outcome = described_class.new( | ||
grid_service: redis_service, | ||
volumes: ['/foo:/foo'] | ||
).run | ||
expect(outcome.success?).to be_truthy | ||
expect(outcome.result.volumes).to eq(['/foo:/foo']) | ||
end | ||
end | ||
|
||
context 'stateful service' do | ||
let(:stateful_service) do | ||
GridService.create( | ||
grid: grid, name: 'redis', image_name: 'redis:2.8', stateful: true, | ||
volumes: ['/data'] | ||
) | ||
end | ||
|
||
it 'does not allow to add non-named volume' do | ||
outcome = described_class.new( | ||
grid_service: stateful_service, | ||
volumes: ['/data', '/foo'] | ||
).run | ||
expect(outcome.success?).to be_falsey | ||
end | ||
|
||
it 'allows to add named volume' do | ||
outcome = described_class.new( | ||
grid_service: stateful_service, | ||
volumes: ['/data', 'foo:/foo'] | ||
).run | ||
expect(outcome.success?).to be_truthy | ||
expect(outcome.result.volumes).to eq(['/data', 'foo:/foo']) | ||
end | ||
|
||
it 'allows to add bind mounted volume' do | ||
outcome = described_class.new( | ||
grid_service: stateful_service, | ||
volumes: ['/data', '/foo:/foo'] | ||
).run | ||
expect(outcome.success?).to be_truthy | ||
expect(outcome.result.volumes).to eq(['/data', '/foo:/foo']) | ||
end | ||
|
||
it 'allows to remove a volume' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing an anonymous
Probably not much of an issue, but that's how it behaves :) |
||
outcome = described_class.new( | ||
grid_service: stateful_service, | ||
volumes: [] | ||
).run | ||
expect(outcome.success?).to be_truthy | ||
expect(outcome.result.volumes).to eq([]) | ||
end | ||
end | ||
end | ||
|
||
context 'volumes_from' do | ||
context 'stateless service' do | ||
it 'allows to update volumes_from' do | ||
outcome = described_class.new( | ||
grid_service: redis_service, | ||
volumes_from: ['data-1'] | ||
).run | ||
expect(outcome.success?).to be_truthy | ||
expect(outcome.result.volumes_from).to eq(['data-1']) | ||
end | ||
end | ||
|
||
context 'stateful service' do | ||
let(:stateful_service) do | ||
GridService.create( | ||
grid: grid, name: 'redis', image_name: 'redis:2.8', stateful: true, | ||
volumes: ['/data'] | ||
) | ||
end | ||
|
||
it 'does not allow to update volumes_from' do | ||
outcome = described_class.new( | ||
grid_service: stateful_service, | ||
volumes_from: ['data-1'] | ||
).run | ||
expect(outcome.success?).to be_falsey | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe '#build_grid_service_hooks' do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor wording fix: "Adding a non-named volume to a stateful service is not supported"