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

Go #1

Open
aibangjuxin opened this issue Sep 21, 2023 · 6 comments
Open

Go #1

aibangjuxin opened this issue Sep 21, 2023 · 6 comments

Comments

@aibangjuxin
Copy link
Owner

学习Go语言并将其应用于GCP GKE的运维工作是一个很好的想法。以下是一些入手的方法和建议:

  1. 基础语法学习

    • 开始学习Go的基础语法,了解变量、函数、数据类型、控制结构等基本概念。可以通过官方文档或在线教程开始。
  2. Go官方文档

    • 阅读Go官方文档是一个很好的方法,它包含了详细的语言规范和示例代码。特别关注包和标准库的部分,这对于开发维护工具非常有用。
  3. 练手项目

    • 创建小型的Go项目,例如命令行工具,以实际动手编写代码。这有助于您熟悉Go的开发流程。
  4. Go Modules

    • 学习如何使用Go Modules管理项目依赖。这对于维护工程师来说很重要,因为您可能需要使用第三方库来构建工具。
  5. 深入了解网络和协议

    • 由于您也有网络方面的知识,深入了解Go中的网络编程以及与TCP和HTTP相关的包。这对于与GCP和GKE进行通信和维护非常有用。
  6. GCP SDK for Go

    • 探索GCP提供的官方Go SDK,以便在Go中与GCP服务进行集成和自动化。
  7. 学习并发编程

    • Go以其强大的并发模型而闻名,学习如何使用goroutines和channels来处理并发任务。
  8. 阅读开源项目

    • 查看一些开源的Go项目,了解其他人是如何使用Go来解决运维和维护方面的问题的。
  9. 在线课程和教程

    • 考虑参加一些在线课程或培训,这些课程通常提供结构化的学习路径和实践机会。
  10. Go社区

    • 参与Go语言社区,通过参与讨论、提问问题和分享经验来学习更多。Go社区非常友好和活跃。

在学习Go的过程中,如果您有具体的问题或需要进一步的解释,请随时向我提问。如果需要生成有关学习Go的流程图或其他内容,也可以提出具体的要求,我将尽力满足您的需求。

@aibangjuxin
Copy link
Owner Author

This script will update network rules that will be applied to all namespaces of the "Runtime" type. It will prohibit these namespaces from outbound traffic to specific IP addresses.

The script will update the network rules, which will be applied to all namespaces with the "Runtime" type. These namespaces will be prohibited from flowing to specific IPs.

@aibangjuxin
Copy link
Owner Author

如果你想从已经配置的gcloud账户中获取账户信息,你可以使用以下方式来实现:

# 获取当前的gcloud账户
current_account=$(gcloud config get-value account)

# 撤销授权
gcloud auth revoke "$sa"

# 设置账户为之前获取的账户
gcloud config set account "$current_account"

这样,脚本首先使用 gcloud config get-value account 命令获取当前的gcloud账户,并将其存储在 current_account 变量中。然后,它执行撤销授权操作,最后再将账户设置为之前获取的账户。这样就能确保在操作之前获取并保存了当前的账户信息。

@aibangjuxin
Copy link
Owner Author

如果你想让以 "sit" 开头的 ${environment} 也执行 "prd" 逻辑,你可以将这两个条件合并在一起,像这样:

if [[ ${environment} == prd* || ${environment} == sit* ]]; then
  echo "Setting proxy prd proxy"
else
  echo "Setting proxy dev proxy"
fi

在这个修改后的脚本中,我使用 || 运算符将两个条件组合在一起。现在,如果 ${environment} 以 "prd" 开头或者以 "sit" 开头,都会执行 "Setting proxy prd proxy" 的逻辑,否则将执行 "Setting proxy dev proxy" 的逻辑。这样就满足了你的要求。

@aibangjuxin
Copy link
Owner Author

if [[ ${environment} == prd* || ${environment} == dev* ]]; then
echo "Setting proxy prd proxy"
else
echo "Setting proxy otherproxy"
fi

@aibangjuxin
Copy link
Owner Author

if [[ ${environment} =~ ^(dev|prd).* ]]; then
echo "Setting proxy prd proxy"
else
echo "Setting proxy otherproxy"
fi

@aibangjuxin
Copy link
Owner Author

To add a condition to the existing script to check if the environment variable environment matches either dev* or prd*, you can use the following syntax:

if [[ ${environment} =~ ^(dev|prd) ]]; then
  echo "Setting proxy prd proxy"
else
  echo "Setting proxy otherproxy"
fi

Here, the =~ operator is used to perform a regular expression match against the value of the environment variable. The regular expression ^(dev|prd) matches any string that starts with either dev or prd.

If the regular expression matches, the script will execute the echo command to print the message "Setting proxy prd proxy". If the regular expression does not match, the script will execute the echo command to print the message "Setting proxy otherproxy".

Note that the ^ anchor at the beginning of the regular expression ensures that the match occurs only at the beginning of the string. This is important because otherwise, the regular expression would also match strings like "devtest" or "prdtest", which may not be desirable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant