-
Notifications
You must be signed in to change notification settings - Fork 40
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
16 changed files
with
328 additions
and
20 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
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
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,99 @@ | ||
require_relative 'base' | ||
|
||
module Kupo::Phases | ||
class ConfigureDNS < Base | ||
# @param master [Kupo::Configuration::Node] | ||
# @param config [Kupo::Config] | ||
def initialize(master, config) | ||
@master = master | ||
@config = config | ||
end | ||
|
||
def call | ||
patch_kubedns( | ||
replicas: @config.dns_replicas, | ||
max_surge: self.max_surge, | ||
max_unavailable: self.max_unavailable, | ||
) | ||
end | ||
|
||
# @return [Integer] | ||
def max_surge | ||
replicas = @config.dns_replicas | ||
nodes = @config.hosts.length | ||
|
||
if replicas == nodes | ||
# cannot create any extra replicas | ||
0 | ||
elsif nodes <= replicas * 1.5 | ||
# at most one per extra node | ||
nodes - replicas | ||
else | ||
# half | ||
(replicas * 0.5).floor | ||
end | ||
end | ||
|
||
# @return [Integer] | ||
def max_unavailable | ||
replicas = @config.dns_replicas | ||
|
||
if replicas == 1 | ||
# must allow taking down all replicas | ||
1 | ||
else | ||
# half | ||
(replicas * 0.5).floor | ||
end | ||
end | ||
|
||
# @param replicas [Integer] | ||
# @param nodes [Integer] | ||
def patch_kubedns(replicas: , max_surge: , max_unavailable: ) | ||
logger.info(@master.address) { "Patching kube-dns addon with #{replicas} replicas (max-surge #{max_surge}, max-unavailable #{max_unavailable})..." } | ||
|
||
kube_client = Kupo::Kube.update_resource(@master.address, Kubeclient::Resource.new({ | ||
apiVersion: 'extensions/v1beta1', | ||
kind: 'Deployment', | ||
metadata: { | ||
namespace: 'kube-system', | ||
name: 'kube-dns', | ||
}, | ||
spec: { | ||
replicas: replicas, | ||
strategy: { | ||
type: "RollingUpdate", | ||
rollingUpdate: { | ||
maxSurge: max_surge, # must be zero for a two-node cluster | ||
maxUnavailable: max_unavailable, # must be at least one, even for a single-node cluster | ||
}, | ||
}, | ||
template: { | ||
spec: { | ||
affinity: { | ||
podAntiAffinity: { | ||
requiredDuringSchedulingIgnoredDuringExecution: [ | ||
{ | ||
labelSelector: { | ||
matchExpressions: [ | ||
{ | ||
key: "k8s-app", | ||
operator: "In", | ||
values: [ | ||
"kube-dns", | ||
], | ||
}, | ||
], | ||
}, | ||
topologyKey: "kubernetes.io/hostname", | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
})) | ||
end | ||
end | ||
end |
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
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
Oops, something went wrong.