generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 13
/
createScopeGcp.go
53 lines (45 loc) · 1.46 KB
/
createScopeGcp.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
package scope
import (
"context"
"encoding/json"
"errors"
"fmt"
cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1"
"github.com/kyma-project/cloud-manager/pkg/composed"
)
func createScopeGcp(ctx context.Context, st composed.State) (error, context.Context) {
logger := composed.LoggerFromCtx(ctx)
state := st.(*State)
js, ok := state.credentialData["serviceaccount.json"]
if !ok {
err := errors.New("gardener credential for gcp missing serviceaccount.json key")
logger.Error(err, "error defining GCP scope")
return composed.StopAndForget, nil // no requeue
}
var data map[string]string
err := json.Unmarshal([]byte(js), &data)
if err != nil {
err := fmt.Errorf("error decoding serviceaccount.json: %w", err)
logger.Error(err, "error defining GCP scope")
return composed.StopAndForget, nil // no requeue
}
project, ok := data["project_id"]
if !ok {
err := errors.New("gardener gcp credentials missing project_id")
logger.Error(err, "error defining GCP scope")
return composed.StopAndForget, nil // no requeue
}
// just create the scope with GCP specifics, the ensureScopeCommonFields will set common values
scope := &cloudcontrolv1beta1.Scope{
Spec: cloudcontrolv1beta1.ScopeSpec{
Scope: cloudcontrolv1beta1.ScopeInfo{
Gcp: &cloudcontrolv1beta1.GcpScope{
Project: project,
VpcNetwork: commonVpcName(state.shootNamespace, state.shootName),
},
},
},
}
state.SetObj(scope)
return nil, nil
}