Skip to content

Commit 2d1bb90

Browse files
authored
feat: adds --disable-streaming flag to cyctl (#614)
1 parent 4dacc0c commit 2d1bb90

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

cyctl/cmd/apply.go

+40-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func doServerSideApply(ctx context.Context, cfg *rest.Config, obj *unstructured.
6767
return err
6868
}
6969

70-
func applyYaml(yamlFile []byte, config *rest.Config, disableTelemetry bool) error {
70+
func applyYaml(yamlFile []byte, config *rest.Config, disableTelemetry bool, disableStreaming bool) error {
7171
multidocReader := utilyaml.NewYAMLReader(bufio.NewReader(bytes.NewReader(yamlFile)))
7272

7373
for {
@@ -85,6 +85,7 @@ func applyYaml(yamlFile []byte, config *rest.Config, disableTelemetry bool) erro
8585
return err
8686
}
8787

88+
// Disable telemetry
8889
if disableTelemetry && obj.GetKind() == "Deployment" && obj.GetName() == "cyclops-ctrl" {
8990
containers, _, _ := unstructured.NestedSlice(obj.Object, "spec", "template", "spec", "containers")
9091
if len(containers) > 0 {
@@ -108,6 +109,34 @@ func applyYaml(yamlFile []byte, config *rest.Config, disableTelemetry bool) erro
108109
}
109110
}
110111

112+
// Disable streaming resources
113+
if disableStreaming && obj.GetKind() == "Deployment" && obj.GetName() == "cyclops-ui" {
114+
containers, _, _ := unstructured.NestedSlice(obj.Object, "spec", "template", "spec", "containers")
115+
if len(containers) > 0 {
116+
container := containers[0].(map[string]interface{})
117+
env, _, _ := unstructured.NestedSlice(container, "env")
118+
119+
for i, e := range env {
120+
soloEnvMap := e.(map[string]interface{})
121+
if soloEnvMap["name"] == "REACT_APP_ENABLE_STREAMING" {
122+
soloEnvMap["value"] = "false"
123+
env[i] = soloEnvMap
124+
break // update the value and break the loop
125+
}
126+
}
127+
err := unstructured.SetNestedSlice(container, env, "env")
128+
if err != nil {
129+
log.Fatal(err)
130+
}
131+
containers[0] = container
132+
err = unstructured.SetNestedSlice(obj.Object, containers, "spec", "template", "spec", "containers")
133+
if err != nil {
134+
log.Fatal(err)
135+
}
136+
fmt.Println("streaming resources are disabled")
137+
}
138+
}
139+
111140
err = doServerSideApply(context.TODO(), config, obj)
112141
if err != nil {
113142
return err
@@ -131,6 +160,11 @@ var applyCmd = &cobra.Command{
131160
log.Fatal(err)
132161
}
133162

163+
disableStreaming, err := cmd.Flags().GetBool("disable-streaming")
164+
if err != nil {
165+
log.Fatal(err)
166+
}
167+
134168
var deployUrl string
135169
var demoUrl string
136170

@@ -159,7 +193,8 @@ var applyCmd = &cobra.Command{
159193

160194
fmt.Println("initializing cyclops resources")
161195

162-
err = applyYaml(deployYamlFile, kubeconfig.Config, disableTelemetry)
196+
// Apply cyclops resources with appropriate flags
197+
err = applyYaml(deployYamlFile, kubeconfig.Config, disableTelemetry, disableStreaming)
163198
if err != nil {
164199
log.Fatal(err)
165200
}
@@ -180,7 +215,7 @@ var applyCmd = &cobra.Command{
180215
}
181216

182217
fmt.Println("creating demo templates")
183-
err = applyYaml(demoYamlFile, kubeconfig.Config, disableTelemetry)
218+
err = applyYaml(demoYamlFile, kubeconfig.Config, disableTelemetry, disableStreaming)
184219
if err != nil {
185220
log.Fatal(err)
186221
}
@@ -190,5 +225,7 @@ var applyCmd = &cobra.Command{
190225
func init() {
191226
applyCmd.Flags().StringP("version", "v", "main", "specify cyclops version")
192227
applyCmd.Flags().BoolP("disable-telemetry", "t", false, "disable emitting telemetry metrics from cyclops controller")
228+
applyCmd.Flags().BoolP("disable-streaming", "s", false, "disable streaming resources from cyclops controller")
229+
193230
RootCmd.AddCommand(applyCmd)
194231
}

0 commit comments

Comments
 (0)