-
Notifications
You must be signed in to change notification settings - Fork 9
/
hooks.go
55 lines (46 loc) · 1.66 KB
/
hooks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2022 Namespace Labs Inc; All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
package kubernetes
import (
"context"
"google.golang.org/protobuf/types/known/anypb"
"namespacelabs.dev/foundation/framework/kubernetes/kubedef"
"namespacelabs.dev/foundation/internal/planning/planninghooks"
"namespacelabs.dev/foundation/internal/runtime/rtypes"
"namespacelabs.dev/foundation/schema"
"namespacelabs.dev/foundation/schema/allocations"
"namespacelabs.dev/foundation/std/cfg"
kubenode "namespacelabs.dev/foundation/std/runtime/kubernetes"
)
func prepareApplyServerExtensions(_ context.Context, _ cfg.Context, srv *schema.Stack_Entry) (*planninghooks.InternalPrepareProps, error) {
var ensureServiceAccount bool
if err := allocations.Visit(srv.Server.Allocation, kubeNode, &kubenode.ServerExtensionArgs{},
func(_ *schema.Allocation_Instance, _ *schema.Instantiate, args *kubenode.ServerExtensionArgs) error {
if args.EnsureServiceAccount {
ensureServiceAccount = true
}
return nil
}); err != nil {
return nil, err
}
if !ensureServiceAccount {
return nil, nil
}
serviceAccount := kubedef.MakeDeploymentId(srv.Server)
packedExt, err := anypb.New(&kubedef.SpecExtension{
EnsureServiceAccount: true,
ServiceAccount: serviceAccount,
})
if err != nil {
return nil, err
}
var props planninghooks.InternalPrepareProps
props.ProvisionInput = []rtypes.ProvisionInput{
{Message: &kubedef.ServiceAccountDetails{ServiceAccountName: serviceAccount}},
}
props.Extension = []*schema.DefExtension{{
Impl: packedExt,
}}
return &props, nil
}