-
Notifications
You must be signed in to change notification settings - Fork 274
Expand file tree
/
Copy pathhelpers.go
More file actions
65 lines (58 loc) · 1.9 KB
/
Copy pathhelpers.go
File metadata and controls
65 lines (58 loc) · 1.9 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
package utils
import (
"context"
"strings"
"github.com/rancher/fleet/pkg/apis/fleet.cattle.io/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
func CreateBundle(ctx context.Context, k8sClient client.Client, name, namespace string, targets []v1alpha1.BundleTarget, targetRestrictions []v1alpha1.BundleTarget) (*v1alpha1.Bundle, error) {
restrictions := []v1alpha1.BundleTargetRestriction{}
for _, r := range targetRestrictions {
restrictions = append(restrictions, v1alpha1.BundleTargetRestriction{
Name: r.Name,
ClusterName: r.ClusterName,
ClusterSelector: r.ClusterSelector,
ClusterGroup: r.ClusterGroup,
ClusterGroupSelector: r.ClusterGroupSelector,
})
}
bundle := v1alpha1.Bundle{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Labels: map[string]string{"foo": "bar"},
},
Spec: v1alpha1.BundleSpec{
Targets: targets,
TargetRestrictions: restrictions,
},
}
return &bundle, k8sClient.Create(ctx, &bundle)
}
func CreateCluster(ctx context.Context, k8sClient client.Client, name, controllerNs string, labels map[string]string, clusterNs string) (*v1alpha1.Cluster, error) {
cluster := &v1alpha1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: controllerNs,
Labels: labels,
},
}
err := k8sClient.Create(ctx, cluster)
if err != nil {
return nil, err
}
cluster.Status.Namespace = clusterNs
err = k8sClient.Status().Update(ctx, cluster)
return cluster, err
}
// ExtractResourceLogs extracts log lines related to a specific resource name
func ExtractResourceLogs(allLogs, resourceName string) string {
var resourceLogs []string
for _, line := range strings.Split(allLogs, "\n") {
if strings.Contains(line, resourceName) {
resourceLogs = append(resourceLogs, line)
}
}
return strings.Join(resourceLogs, "\n")
}