Skip to content

Commit c2046fd

Browse files
committed
Add record and replay
1 parent 6278a65 commit c2046fd

28 files changed

+2324
-2
lines changed

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@ require (
77
github.com/gogo/protobuf v1.3.2
88
github.com/google/go-cmp v0.7.0
99
github.com/spf13/cobra v1.8.1
10+
github.com/wzshiming/getch v0.0.0-20201023133301-8e758c21cf27
1011
go.etcd.io/etcd/api/v3 v3.5.21
1112
go.etcd.io/etcd/client/pkg/v3 v3.5.21
1213
go.etcd.io/etcd/client/v3 v3.5.21
14+
golang.org/x/term v0.30.0
1315
k8s.io/api v0.33.0
1416
k8s.io/apimachinery v0.33.0
1517
k8s.io/client-go v0.33.0
18+
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
1619
sigs.k8s.io/e2e-framework v0.6.0
1720
sigs.k8s.io/yaml v1.4.0
1821
)
@@ -59,7 +62,6 @@ require (
5962
golang.org/x/net v0.38.0 // indirect
6063
golang.org/x/oauth2 v0.27.0 // indirect
6164
golang.org/x/sys v0.31.0 // indirect
62-
golang.org/x/term v0.30.0 // indirect
6365
golang.org/x/text v0.23.0 // indirect
6466
golang.org/x/time v0.9.0 // indirect
6567
google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7 // indirect
@@ -72,7 +74,6 @@ require (
7274
k8s.io/component-base v0.32.1 // indirect
7375
k8s.io/klog/v2 v2.130.1 // indirect
7476
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
75-
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
7677
sigs.k8s.io/controller-runtime v0.20.0 // indirect
7778
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
7879
sigs.k8s.io/randfill v1.0.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
120120
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
121121
github.com/vladimirvivien/gexe v0.4.1 h1:W9gWkp8vSPjDoXDu04Yp4KljpVMaSt8IQuHswLDd5LY=
122122
github.com/vladimirvivien/gexe v0.4.1/go.mod h1:3gjgTqE2c0VyHnU5UOIwk7gyNzZDGulPb/DJPgcw64E=
123+
github.com/wzshiming/getch v0.0.0-20201023133301-8e758c21cf27 h1:jKLZ5tGpOZRid6GpBbDmP4BiooSF5zDd7Cg9jHCN4Yk=
124+
github.com/wzshiming/getch v0.0.0-20201023133301-8e758c21cf27/go.mod h1:TYK5eJtSD5cVebob9fE7D3jR1fbRU1EwkoPzbLWsOAk=
123125
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
124126
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
125127
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=

pkg/apis/action/v1alpha1/doc.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// +k8s:deepcopy-gen=package
18+
// +k8s:defaulter-gen=TypeMeta
19+
// +groupName=action.kwok.x-k8s.io
20+
21+
// Package v1alpha1 implements the v1alpha1 apiVersion of kwokctl's action
22+
package v1alpha1
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
"k8s.io/apimachinery/pkg/runtime/schema"
21+
)
22+
23+
var (
24+
// GroupVersion is group version used to register these objects
25+
GroupVersion = schema.GroupVersion{
26+
Group: "action.kwok.x-k8s.io",
27+
Version: "v1alpha1",
28+
}
29+
)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
Copyright 2024 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
"encoding/json"
21+
"time"
22+
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
)
25+
26+
const (
27+
// ResourcePatchKind is the kind of the ResourcePatch.
28+
ResourcePatchKind = "ResourcePatch"
29+
)
30+
31+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
32+
33+
// ResourcePatch provides resource definition for kwokctl.
34+
// this is a action of resource patch.
35+
type ResourcePatch struct {
36+
//+k8s:conversion-gen=false
37+
metav1.TypeMeta `json:",inline"`
38+
39+
// Resource represents the resource to be patched.
40+
Resource GroupVersionResource `json:"resource"`
41+
// Target represents the target of the ResourcePatch.
42+
Target Target `json:"target"`
43+
// DurationNanosecond represents the duration of the patch in nanoseconds.
44+
DurationNanosecond time.Duration `json:"durationNanosecond"`
45+
// Method represents the method of the patch.
46+
Method PatchMethod `json:"method"`
47+
// Template contains the patch data as a raw JSON message.
48+
Template json.RawMessage `json:"template,omitempty"`
49+
}
50+
51+
// PatchMethod defines the method used to patch a resource.
52+
type PatchMethod string
53+
54+
const (
55+
// PatchMethodCreate means that the resource will be created by create.
56+
PatchMethodCreate PatchMethod = "create"
57+
// PatchMethodPatch means that the resource will be patched by patch.
58+
PatchMethodPatch PatchMethod = "patch"
59+
// PatchMethodDelete means that the resource will be deleted by delete.
60+
PatchMethodDelete PatchMethod = "delete"
61+
)
62+
63+
// Target is a struct that represents the target of the ResourcePatch.
64+
type Target struct {
65+
// Name represents the name of the resource to be patched.
66+
Name string `json:"name"`
67+
// Namespace represents the namespace of the resource to be patched.
68+
Namespace string `json:"namespace,omitempty"`
69+
}
70+
71+
// GroupVersionResource is a struct that represents the group version resource.
72+
type GroupVersionResource struct {
73+
// Group represents the group of the resource.
74+
Group string `json:"group,omitempty"`
75+
// Version represents the version of the resource.
76+
Version string `json:"version"`
77+
// Resource represents the type of the resource.
78+
Resource string `json:"resource"`
79+
}

pkg/apis/action/v1alpha1/zz_generated.deepcopy.go

Lines changed: 92 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/action/v1alpha1/zz_generated.defaults.go

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cmd/ctl.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ func NewCtlCommand() *cobra.Command {
7777
newCtlGetCommand(),
7878
newCtlDelCommand(),
7979
newCtlPutCommand(),
80+
81+
newCtlRecordCommand(),
82+
newCtlReplayCommand(),
8083
)
8184
return cmd
8285
}

pkg/cmd/global.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"go.etcd.io/etcd/client/pkg/v3/srv"
3434
"go.etcd.io/etcd/client/pkg/v3/transport"
3535
clientv3 "go.etcd.io/etcd/client/v3"
36+
"golang.org/x/term"
3637

3738
_ "github.com/kwok-ci/kectl/pkg/old/scheme"
3839
)
@@ -336,3 +337,8 @@ func endpointsFromFlagValue(cmd *cobra.Command) ([]string, error) {
336337
}
337338
return ret, err
338339
}
340+
341+
// isTerminal returns true if the given file descriptor is a terminal.
342+
func isTerminal() bool {
343+
return term.IsTerminal(int(os.Stdout.Fd()))
344+
}

0 commit comments

Comments
 (0)