Skip to content

Commit 536800d

Browse files
author
Martin Linkhorst
committed
remove the hook in favour of inline processing
1 parent eeae7a0 commit 536800d

File tree

4 files changed

+57
-109
lines changed

4 files changed

+57
-109
lines changed

cmd/clm/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ func main() {
135135
secretDecrypter,
136136
cfg.AssumedRole,
137137
awsConfig,
138+
clusterRegistry,
138139
&provisioner.Options{
139140
DryRun: cfg.DryRun,
140141
ApplyOnly: cfg.ApplyOnly,
141142
UpdateStrategy: cfg.UpdateStrategy,
142143
RemoveVolumes: cfg.RemoveVolumes,
143-
Hook: provisioner.NewZalandoEKSCreationHook(clusterRegistry),
144144
},
145145
),
146146
}

provisioner/clusterpy.go

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package provisioner
33
import (
44
"bytes"
55
"context"
6+
"encoding/base64"
67
"fmt"
78
"io"
89
"net/http"
@@ -25,6 +26,7 @@ import (
2526
"github.com/zalando-incubator/cluster-lifecycle-manager/pkg/kubernetes"
2627
"github.com/zalando-incubator/cluster-lifecycle-manager/pkg/updatestrategy"
2728
"github.com/zalando-incubator/cluster-lifecycle-manager/pkg/util/command"
29+
"github.com/zalando-incubator/cluster-lifecycle-manager/registry"
2830
"github.com/zalando-incubator/kube-ingress-aws-controller/certs"
2931
"golang.org/x/oauth2"
3032
"gopkg.in/yaml.v2"
@@ -71,7 +73,7 @@ type clusterpyProvisioner struct {
7173
tokenSource oauth2.TokenSource
7274
applyOnly bool
7375
updateStrategy config.UpdateStrategy
74-
hook CreationHook
76+
clusterRegistry registry.Registry
7577
removeVolumes bool
7678
manageEtcdStack bool
7779
manageMasterNodes bool
@@ -298,17 +300,62 @@ func (p *clusterpyProvisioner) provision(
298300
return err
299301
}
300302

301-
var postOptions *HookResponse
302-
if p.hook != nil {
303-
postOptions, err = p.hook.Execute(
304-
awsAdapter,
305-
cluster,
306-
outputs,
303+
postOptions := &HookResponse{}
304+
305+
if cluster.Provider == string(ZalandoEKSProvider) {
306+
clusterDetails, err := awsAdapter.GetEKSClusterDetails(cluster)
307+
if err != nil {
308+
return err
309+
}
310+
decodedCA, err := base64.StdEncoding.DecodeString(
311+
clusterDetails.CertificateAuthority,
307312
)
308313
if err != nil {
309314
return err
310315
}
311316

317+
if cluster.ConfigItems == nil {
318+
cluster.ConfigItems = map[string]string{}
319+
}
320+
321+
toUpdate := map[string]string{}
322+
if cluster.ConfigItems[KeyEKSEndpoint] != clusterDetails.Endpoint {
323+
toUpdate[KeyEKSEndpoint] = clusterDetails.Endpoint
324+
}
325+
if cluster.ConfigItems[KeyEKSCAData] != clusterDetails.CertificateAuthority {
326+
toUpdate[KeyEKSCAData] = clusterDetails.CertificateAuthority
327+
}
328+
if cluster.ConfigItems[KeyEKSOIDCIssuerURL] != clusterDetails.OIDCIssuerURL {
329+
toUpdate[KeyEKSOIDCIssuerURL] = clusterDetails.OIDCIssuerURL
330+
}
331+
332+
err = p.clusterRegistry.UpdateConfigItems(cluster, toUpdate)
333+
if err != nil {
334+
return err
335+
}
336+
337+
postOptions.APIServerURL = clusterDetails.Endpoint
338+
postOptions.CAData = decodedCA
339+
340+
subnets := map[string]string{}
341+
for key, az := range map[string]string{
342+
"EKSSubneta": "eu-central-1a",
343+
"EKSSubnetb": "eu-central-1b",
344+
"EKSSubnetc": "eu-central-1c",
345+
} {
346+
if v, ok := outputs[key]; ok {
347+
subnets[az] = v
348+
}
349+
}
350+
if len(subnets) > 0 {
351+
postOptions.AZInfo = &AZInfo{
352+
subnets: subnets,
353+
}
354+
postOptions.TemplateValues = map[string]interface{}{
355+
subnetsValueKey: subnets,
356+
}
357+
}
358+
312359
if postOptions.APIServerURL != "" {
313360
cluster.APIServerURL = postOptions.APIServerURL
314361
}

provisioner/provisioner.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,6 @@ type (
3333
) error
3434
}
3535

36-
// CreationHook is an interface that provisioners can use while provisioning
37-
// a cluster.
38-
//
39-
// This is useful for example to pass additional configuration only known at
40-
// a later stage of provisioning. For example, when provisioning an EKS
41-
// cluster, the provisioner only knows what is the API Server URL after
42-
// applying the initial CloudFormation.
43-
CreationHook interface {
44-
// Execute performs updates used by a provisioner during cluster
45-
// creation.
46-
Execute(
47-
adapter awsInterface,
48-
cluster *api.Cluster,
49-
cloudFormationOutput map[string]string,
50-
) (
51-
*HookResponse,
52-
error,
53-
)
54-
}
55-
5636
// HookResponse contain configuration parameters that a provisioner can use
5737
// at a later stage.
5838
HookResponse struct {
@@ -69,7 +49,6 @@ type (
6949
UpdateStrategy config.UpdateStrategy
7050
RemoveVolumes bool
7151
ManageEtcdStack bool
72-
Hook CreationHook
7352
}
7453
)
7554

provisioner/zalando_eks.go

Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func NewZalandoEKSProvisioner(
3939
secretDecrypter decrypter.Decrypter,
4040
assumedRole string,
4141
awsConfig *aws.Config,
42+
clusterRegistry registry.Registry,
4243
options *Options,
4344
) Provisioner {
4445
provisioner := &ZalandoEKSProvisioner{
@@ -49,6 +50,7 @@ func NewZalandoEKSProvisioner(
4950
secretDecrypter: secretDecrypter,
5051
manageMasterNodes: false,
5152
manageEtcdStack: false,
53+
clusterRegistry: clusterRegistry,
5254
},
5355
}
5456

@@ -57,7 +59,6 @@ func NewZalandoEKSProvisioner(
5759
provisioner.applyOnly = options.ApplyOnly
5860
provisioner.updateStrategy = options.UpdateStrategy
5961
provisioner.removeVolumes = options.RemoveVolumes
60-
provisioner.hook = options.Hook
6162
}
6263

6364
return provisioner
@@ -138,82 +139,3 @@ func (z *ZalandoEKSProvisioner) Decommission(
138139
caData,
139140
)
140141
}
141-
142-
// NewZalandoEKSCreationHook returns a new hook for EKS cluster provisioning,
143-
// configured to use the given cluster registry.
144-
func NewZalandoEKSCreationHook(
145-
clusterRegistry registry.Registry,
146-
) CreationHook {
147-
return &ZalandoEKSCreationHook{
148-
clusterRegistry: clusterRegistry,
149-
}
150-
}
151-
152-
// Execute updates the configuration only known after deploying the first
153-
// CloudFormation stack.
154-
//
155-
// The method returns the API server URL, the Certificate Authority data,
156-
// and the subnets. Additionally Execute updates the configured cluster
157-
// registry with the EKS API Server URL and the Certificate Authority data.
158-
func (z *ZalandoEKSCreationHook) Execute(
159-
adapter awsInterface,
160-
cluster *api.Cluster,
161-
cloudFormationOutput map[string]string,
162-
) (*HookResponse, error) {
163-
res := &HookResponse{}
164-
165-
clusterDetails, err := adapter.GetEKSClusterDetails(cluster)
166-
if err != nil {
167-
return nil, err
168-
}
169-
decodedCA, err := base64.StdEncoding.DecodeString(
170-
clusterDetails.CertificateAuthority,
171-
)
172-
if err != nil {
173-
return nil, err
174-
}
175-
176-
if cluster.ConfigItems == nil {
177-
cluster.ConfigItems = map[string]string{}
178-
}
179-
180-
toUpdate := map[string]string{}
181-
if cluster.ConfigItems[KeyEKSEndpoint] != clusterDetails.Endpoint {
182-
toUpdate[KeyEKSEndpoint] = clusterDetails.Endpoint
183-
}
184-
if cluster.ConfigItems[KeyEKSCAData] != clusterDetails.CertificateAuthority {
185-
toUpdate[KeyEKSCAData] = clusterDetails.CertificateAuthority
186-
}
187-
if cluster.ConfigItems[KeyEKSOIDCIssuerURL] != clusterDetails.OIDCIssuerURL {
188-
toUpdate[KeyEKSOIDCIssuerURL] = clusterDetails.OIDCIssuerURL
189-
}
190-
191-
err = z.clusterRegistry.UpdateConfigItems(cluster, toUpdate)
192-
if err != nil {
193-
return nil, err
194-
}
195-
196-
res.APIServerURL = clusterDetails.Endpoint
197-
res.CAData = decodedCA
198-
199-
subnets := map[string]string{}
200-
for key, az := range map[string]string{
201-
"EKSSubneta": "eu-central-1a",
202-
"EKSSubnetb": "eu-central-1b",
203-
"EKSSubnetc": "eu-central-1c",
204-
} {
205-
if v, ok := cloudFormationOutput[key]; ok {
206-
subnets[az] = v
207-
}
208-
}
209-
if len(subnets) > 0 {
210-
res.AZInfo = &AZInfo{
211-
subnets: subnets,
212-
}
213-
res.TemplateValues = map[string]interface{}{
214-
subnetsValueKey: subnets,
215-
}
216-
}
217-
218-
return res, nil
219-
}

0 commit comments

Comments
 (0)