-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathservicemesh.go
More file actions
134 lines (118 loc) · 3.62 KB
/
Copy pathservicemesh.go
File metadata and controls
134 lines (118 loc) · 3.62 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package profile
import (
"fmt"
"time"
"github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/apiextensions"
metav1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/meta/v1"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"k8s.io/apimachinery/pkg/runtime/schema"
)
const (
istioSystemNamespace = "istio-system"
istioCNINamespace = "istio-cni"
)
var (
istioGVR = schema.GroupVersionResource{
Group: "sailoperator.io",
Version: "v1",
Resource: "istios",
}
istioCNIGVR = schema.GroupVersionResource{
Group: "sailoperator.io",
Version: "v1",
Resource: "istiocnis",
}
)
func deployServiceMesh(ctx *pulumi.Context, args *DeployArgs) (pulumi.Resource, error) {
goCtx := ctx.Context()
rn := func(suffix string) string {
return fmt.Sprintf("%s-smesh-%s", args.Prefix, suffix)
}
nsSystem, err := args.newNamespace(ctx, rn("ns-system"), pulumi.String(istioSystemNamespace), pulumi.DependsOn(args.Deps))
if err != nil {
return nil, err
}
nsCNI, err := args.newNamespace(ctx, rn("ns-cni"), pulumi.String(istioCNINamespace), pulumi.DependsOn(args.Deps))
if err != nil {
return nil, err
}
// Install the Service Mesh 3 operator (installs into openshift-operators)
csvReady, err := installOperator(ctx, args, operatorInstall{
resourcePrefix: rn(""),
namespace: "openshift-operators",
subName: "servicemeshoperator3",
packageName: "servicemeshoperator3",
csvPrefix: "servicemeshoperator3",
extraDeps: []pulumi.Resource{nsSystem, nsCNI},
})
if err != nil {
return nil, err
}
// Create IstioCNI CR (cluster-scoped)
istioCNIName := csvReady.ApplyT(func(_ string) string {
return "default"
}).(pulumi.StringOutput)
cni, err := apiextensions.NewCustomResource(ctx, rn("istiocni"),
&apiextensions.CustomResourceArgs{
ApiVersion: pulumi.String("sailoperator.io/v1"),
Kind: pulumi.String("IstioCNI"),
Metadata: &metav1.ObjectMetaArgs{
Name: istioCNIName,
},
OtherFields: map[string]interface{}{
"spec": map[string]interface{}{
"namespace": istioCNINamespace,
"profile": "openshift",
},
},
},
args.k8sOpts()...)
if err != nil {
return nil, err
}
// Wait for IstioCNI to be ready
cniReady := pulumi.All(cni.ID(), args.Kubeconfig).ApplyT(
func(allArgs []interface{}) (string, error) {
kc := allArgs[1].(string)
if err := waitForCRCondition(goCtx, kc, istioCNIGVR,
"", "default",
"", "Ready", "True", 20*time.Minute, false); err != nil {
return "", fmt.Errorf("waiting for IstioCNI: %w", err)
}
return "ready", nil
}).(pulumi.StringOutput)
// Create Istio CR (cluster-scoped, depends on CNI being ready)
istioName := cniReady.ApplyT(func(_ string) string {
return "default"
}).(pulumi.StringOutput)
istio, err := apiextensions.NewCustomResource(ctx, rn("istio"),
&apiextensions.CustomResourceArgs{
ApiVersion: pulumi.String("sailoperator.io/v1"),
Kind: pulumi.String("Istio"),
Metadata: &metav1.ObjectMetaArgs{
Name: istioName,
},
OtherFields: map[string]interface{}{
"spec": map[string]interface{}{
"namespace": istioSystemNamespace,
},
},
},
args.k8sOpts()...)
if err != nil {
return nil, err
}
// Wait for Istio to be ready
istioReady := pulumi.All(istio.ID(), args.Kubeconfig).ApplyT(
func(allArgs []interface{}) (string, error) {
kc := allArgs[1].(string)
if err := waitForCRCondition(goCtx, kc, istioGVR,
"", "default",
"", "Ready", "True", 20*time.Minute, false); err != nil {
return "", fmt.Errorf("waiting for Istio: %w", err)
}
return "ready", nil
}).(pulumi.StringOutput)
ctx.Export("istioReady", istioReady)
return istio, nil
}