Skip to content

Commit ec69489

Browse files
zongzwgitee-org
authored andcommitted
!43 delete partition when gatewayclass is removed.
Merge pull request !43 from zongzw/zong-delete-partition
2 parents 373f603 + 0fee4c1 commit ec69489

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

controllers/gatewayclass_controller.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,15 @@ func handleDeletingGatewayClass(ctx context.Context, req ctrl.Request) (ctrl.Res
128128
return ctrl.Result{}, err
129129
}
130130

131+
dctx := context.WithValue(ctx, pkg.CtxKey_DeletePartition, "yes")
131132
pkg.PendingDeploys <- pkg.DeployRequest{
132133
Meta: fmt.Sprintf("clearing gateways for gatewayclass '%s'", req.Name),
133134
From: &ocfgs,
134135
To: nil,
135136
StatusFunc: func() {
136137
},
137138
Partition: req.Name,
138-
Context: ctx,
139+
Context: dctx,
139140
}
140141

141142
pkg.PendingDeploys <- pkg.DeployRequest{
@@ -197,13 +198,14 @@ func handleUpsertingGatewayClass(ctx context.Context, obj *gatewayv1beta1.Gatewa
197198
Context: ctx,
198199
}
199200

201+
cctx := context.WithValue(ctx, pkg.CtxKey_CreatePartition, "yes")
200202
pkg.PendingDeploys <- pkg.DeployRequest{
201203
Meta: fmt.Sprintf("refreshing gateways for gatewayclass '%s'", reqn),
202204
From: &ocfgs,
203205
To: &ncfgs,
204206
StatusFunc: func() {},
205207
Partition: reqn,
206-
Context: ctx,
208+
Context: cctx,
207209
}
208210

209211
return ctrl.Result{}, nil

pkg/deployer.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import (
88
func deploy(bc *f5_bigip.BIGIPContext, partition string, ocfgs, ncfgs *map[string]interface{}) error {
99
defer utils.TimeItToPrometheus()()
1010

11-
if err := bc.DeployPartition(partition); err != nil {
12-
return err
13-
}
14-
1511
cmds, err := bc.GenRestRequests(partition, ocfgs, ncfgs)
1612
if err != nil {
1713
return err
@@ -83,10 +79,23 @@ func Deployer(stopCh chan struct{}, bigips []*f5_bigip.BIGIP) {
8379
go func(bc *f5_bigip.BIGIPContext, r DeployRequest) {
8480
defer func() { done <- true }()
8581

82+
if r.Context.Value(CtxKey_CreatePartition) != nil {
83+
if err := bc.DeployPartition(r.Partition); err != nil {
84+
slog.Errorf("failed to deploy partition %s: %s", r.Partition, err.Error())
85+
return
86+
}
87+
}
8688
err := deploy(bc, r.Partition, r.From, r.To)
8789
if err != nil {
8890
// report the error to status or ...
8991
slog.Errorf("failed to do deployment to %s: %s", bc.URL, err.Error())
92+
return
93+
}
94+
if r.Context.Value(CtxKey_DeletePartition) != nil {
95+
if err := bc.DeletePartition(r.Partition); err != nil {
96+
slog.Errorf("failed to deploy partition %s: %s", r.Partition, err.Error())
97+
return
98+
}
9099
}
91100
r.StatusFunc()
92101
}(bc, r)

pkg/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ type DeployRequest struct {
1818
Context context.Context
1919
}
2020

21+
type CtxKeyType string
22+
2123
type ParseRequest struct {
2224
Gateway *gatewayv1beta1.Gateway
2325
HTTPRoute *gatewayv1beta1.HTTPRoute

pkg/vars.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ var (
77
AllBigipConfigs BigipConfigs
88
// slog utils.SLOG
99
)
10+
11+
const (
12+
CtxKey_DeletePartition CtxKeyType = "delete_partition"
13+
CtxKey_CreatePartition CtxKeyType = "create_partition"
14+
)

0 commit comments

Comments
 (0)