Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disable telemetry with init #412

Merged
merged 5 commits into from
Jul 17, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions cyctl/cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func doServerSideApply(ctx context.Context, cfg *rest.Config, obj *unstructured.
return err
}

func applyYaml(yamlFile []byte, config *rest.Config) error {
func applyYaml(yamlFile []byte, config *rest.Config, telemetry bool) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also rename this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

multidocReader := utilyaml.NewYAMLReader(bufio.NewReader(bytes.NewReader(yamlFile)))

for {
Expand All @@ -85,6 +85,29 @@ func applyYaml(yamlFile []byte, config *rest.Config) error {
return err
}

if telemetry && obj.GetKind() == "Deployment" && obj.GetName() == "cyclops-ctrl" {
containers, _, _ := unstructured.NestedSlice(obj.Object, "spec", "template", "spec", "containers")
if len(containers) > 0 {
container := containers[0].(map[string]interface{})
env, _, _ := unstructured.NestedSlice(container, "env")
newEnv := map[string]interface{}{
"name": "DISABLE_TELEMETRY",
"value": "true",
}
env = append(env, newEnv)
err := unstructured.SetNestedSlice(container, env, "env")
if err != nil {
log.Fatal(err)
}
containers[0] = container
err = unstructured.SetNestedSlice(obj.Object, containers, "spec", "template", "spec", "containers")
if err != nil {
log.Fatal(err)
}
fmt.Println("telemetry is disabled")
}
}

err = doServerSideApply(context.TODO(), config, obj)
if err != nil {
return err
Expand All @@ -103,6 +126,8 @@ var applyCmd = &cobra.Command{
log.Fatal(err)
}

telemetry, _ := cmd.Flags().GetBool("disable-telemetry")
thebigbone marked this conversation as resolved.
Show resolved Hide resolved

var deployUrl string
var demoUrl string

Expand Down Expand Up @@ -131,7 +156,7 @@ var applyCmd = &cobra.Command{

fmt.Println("initializing cyclops resources")

err = applyYaml(deployYamlFile, kubeconfig.Config)
err = applyYaml(deployYamlFile, kubeconfig.Config, telemetry)
if err != nil {
log.Fatal(err)
}
Expand All @@ -152,7 +177,7 @@ var applyCmd = &cobra.Command{
}

fmt.Println("creating demo templates")
err = applyYaml(demoYamlFile, kubeconfig.Config)
err = applyYaml(demoYamlFile, kubeconfig.Config, telemetry)
if err != nil {
log.Fatal(err)
}
Expand All @@ -161,5 +186,6 @@ var applyCmd = &cobra.Command{

func init() {
applyCmd.Flags().StringP("version", "v", "main", "specify cyclops version")
applyCmd.Flags().BoolP("disable-telemetry", "t", false, "disable emitting telemetry metrics from cyclops controller")
RootCmd.AddCommand(applyCmd)
}
Loading