-
Notifications
You must be signed in to change notification settings - Fork 3
/
4.go
58 lines (45 loc) · 1.29 KB
/
4.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
56
57
58
package challenges
import (
"context"
"time"
apiv1 "k8s.io/api/core/v1"
networkv1 "k8s.io/api/networking/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
var challenge4 = Challenge{
Name: "Fear and Loathing with network policies 🕸️",
Description: "What's in a policy ¯\\_(ツ)_/¯",
AllowedTime: 4 * time.Minute,
DeployFunc: func(ctx context.Context, clientSet *kubernetes.Clientset, r *rest.Config) error {
replicas := int32(2)
backEndDeployment.Spec.Replicas = &replicas
// Create Network Policy
net := &networkv1.NetworkPolicy{
ObjectMeta: v1.ObjectMeta{
Name: "hive-policy",
},
Spec: networkv1.NetworkPolicySpec{
PodSelector: *&v1.LabelSelector{
MatchLabels: map[string]string{
"app": "middle", // RUHROH
},
},
Ingress: []networkv1.NetworkPolicyIngressRule{},
},
}
clientSet.NetworkingV1().NetworkPolicies(apiv1.NamespaceDefault).Create(ctx, net, v1.CreateOptions{})
return deployObjects(ctx, clientSet, false)
},
Readme: `
Welcome to "The Hive"
--------------------------------
Enable hubble (optional)
-------------
kubectl expose -n kube-system deploy hubble-ui --type=NodePort --name hubble-node
`,
}
func init() {
Challenges = append(Challenges, challenge4)
}