MCPcopy
hub / github.com/kubernetes/kops / addAWSVolume

Method addAWSVolume

pkg/model/master_volumes.go:139–207  ·  view source on GitHub ↗
(c *fi.CloudupModelBuilderContext, name string, volumeSize int32, zone string, etcd kops.EtcdClusterSpec, m kops.EtcdMemberSpec, allMembers []string)

Source from the content-addressed store, hash-verified

137}
138
139func (b *MasterVolumeBuilder) addAWSVolume(c *fi.CloudupModelBuilderContext, name string, volumeSize int32, zone string, etcd kops.EtcdClusterSpec, m kops.EtcdMemberSpec, allMembers []string) error {
140 // https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html
141 volumeType := fi.ValueOf(m.VolumeType)
142 if volumeType == "" {
143 volumeType = DefaultAWSEtcdVolumeType
144 }
145 volumeIops := fi.ValueOf(m.VolumeIOPS)
146 volumeThroughput := fi.ValueOf(m.VolumeThroughput)
147 switch ec2types.VolumeType(volumeType) {
148 case ec2types.VolumeTypeIo1, ec2types.VolumeTypeIo2:
149 if volumeIops < 100 {
150 volumeIops = DefaultAWSEtcdVolumeIonIops
151 }
152 case ec2types.VolumeTypeGp3:
153 if volumeIops < 3000 {
154 volumeIops = DefaultAWSEtcdVolumeGp3Iops
155 }
156 if volumeThroughput < 125 {
157 volumeThroughput = DefaultAWSEtcdVolumeGp3Throughput
158 }
159 }
160
161 if err := validateAWSVolume(name, volumeType, volumeSize, volumeIops, volumeThroughput); err != nil {
162 return err
163 }
164
165 // The tags are how protokube knows to mount the volume and use it for etcd
166 tags := make(map[string]string)
167
168 // Apply all user defined labels on the volumes
169 for k, v := range b.Cluster.Spec.CloudLabels {
170 tags[k] = v
171 }
172
173 // tags[awsup.TagClusterName] = b.C.cluster.Name
174 // This is the configuration of the etcd cluster
175 tags[awsup.TagNameEtcdClusterPrefix+etcd.Name] = m.Name + "/" + strings.Join(allMembers, ",")
176 // This says "only mount on a control plane node"
177 tags[awsup.TagNameRolePrefix+"control-plane"] = "1"
178 tags[awsup.TagNameRolePrefix+"master"] = "1"
179
180 // We always add an owned tags (these can't be shared)
181 tags["kubernetes.io/cluster/"+b.Cluster.ObjectMeta.Name] = "owned"
182
183 encrypted := fi.ValueOf(m.EncryptedVolume)
184
185 t := &awstasks.EBSVolume{
186 Name: fi.PtrTo(name),
187 Lifecycle: b.Lifecycle,
188
189 AvailabilityZone: fi.PtrTo(zone),
190 SizeGB: fi.PtrTo(int32(volumeSize)),
191 VolumeType: ec2types.VolumeType(volumeType),
192 KmsKeyId: m.KmsKeyID,
193 Encrypted: fi.PtrTo(encrypted),
194 Tags: tags,
195 }
196 switch ec2types.VolumeType(volumeType) {

Callers 1

BuildMethod · 0.95

Calls 5

ValueOfFunction · 0.92
PtrToFunction · 0.92
validateAWSVolumeFunction · 0.85
AddTaskMethod · 0.80
JoinMethod · 0.65

Tested by

no test coverage detected