ACK One GitOps provides continuous delivery for multi-cluster applications in hybrid cloud, multicloud, and multi-cluster scenarios. It is built on a managed open source Argo CD and is fully compatible with Argo CD APIs, such as the Application API. Compared with open source Argo CD, ACK One GitOps offers advantages such as multi-cluster distribution, multi-user permission management, and out-of-the-box, O&M-free use. To integrate ACK One GitOps into your application release system, you can use the Go SDK to create, delete, or sync Argo CD Applications. This topic uses Argo CD v2.9.3 as an example to demonstrate how to create an Application using the Go SDK.
Demo code configuration
Step 1: Get the Server or Name of the target cluster
You must specify the Server or Name of the target cluster in the Argo CD Application.
Obtain the KubeConfig file of the fleet instance from the ACK One console and use kubectl to connect to the fleet instance.
For more information, see Obtain the KubeConfig of a cluster and use kubectl to connect to the cluster.
Run one of the following commands to retrieve the list of
NameorServervalues for all associated clusters. You only need to select one. TheNameis more readable and uses the format<cluster id>-<cluster name>by default.Retrieve the list of
Namevalueskubectl get secret -nargocd -l argocd.argoproj.io/secret-type=cluster |awk 'NR>1 {print $1}'|xargs -I {} sh -c 'kubectl get secret -nargocd {} -ojsonpath="{.data.name}"|base64 -d; echo'Retrieve the list of
Servervalueskubectl get secret -nargocd -l argocd.argoproj.io/secret-type=cluster |awk 'NR>1 {print $1}'|xargs -I {} sh -c 'kubectl get secret -nargocd {} -ojsonpath="{.data.server}"|base64 -d; echo'
Step 2: Get a token
Create a local user in the fleet instance and generate a token for the user to manage Application operations.
Create a local user.
Run the following command to edit the
argocd-cmConfigMap of Argo CD.kubectl edit cm argocd-cm -n argocdIn the
argocd-cmConfigMap, add a local user namedlocaluser1as shown in the following code.data: accounts.localuser1: login,apiKey # Allow the local user to log on to the Argo CD UI and the Argo CD CLI, and generate an apiKey token. accounts.localuser1.enabled: "true" # Create local user localuser1.Run the following command to query the local user:
argocd account listExpected output:
NAME ENABLED CAPABILITIES admin true login localuser1 true login,apiKey # The local user localuser1.
In
argocd-rbac-cm, grant Role-Based Access Control (RBAC) permissions for the Kubernetes resources of Argo CD to the local user that you created. For example, you can grant the admin role, which has read and write permissions on resources such as applications, clusters, and projects.For more information about Argo CD RBAC permissions, see Configure Argo CD RBAC for a user.
Run the following command to edit the
argocd-rbac-cmConfigMap of Argo CD.kubectl edit cm argocd-rbac-cm -n argocdIn the
argocd-rbac-cmConfigMap file, grant permissions to the local user as shown in the following example.ImportantDo not modify the existing configurations in this ConfigMap file.
data: policy.csv: | g, "14***01", role:admin # Existing configuration. Do not modify. g, localuser1, role:admin # New configuration. Maps localuser1 to the admin role. scopes: '[uid]'
Generate a token for the local user.
Generate a token using the Argo CD CLI
Run the following command to set a password and generate a token:
# Set a password. argocd account update-password \ --account localuser1 \ --current-password <admin password> \ --new-password <localuser1-password> # Generate a token for localuser1. argocd account generate-token --account localuser1 eyJhb......Generate a token using the Argo CD UI
Log on to the ACK One console. In the left-side navigation pane, choose .
On the Multi-cluster GitOps page, click the
icon next to the fleet name in the upper-left corner. From the drop-down list, select the target fleet. Then, click GitOps Console. On the logon page that appears, enter the username and password to log on.In the navigation pane on the left of the Argo CD console, choose Settings, and then choose Accounts. Find the local user that you added and click the username. This topic uses localuser1 as an example.
On the user page for localuser1, click Generate New in the Tokens section and save the token.
Step 3: Sample code for Application operations
The following sample code shows how to perform application operations, including creating, syncing, retrieving the details of, updating, and deleting an application.
Main entry point.
NoteReplace
<argocd server lb ip>with the IP address of the Argo CD server load balancer, which you can obtain by running thekubectl get svc -nargocd argocd-server -ojsonpath='{.status.loadBalancer.ingress[0].ip}'command.Replace
local user tokenwith the token that you obtained in Step 2: Obtain a token.
Sample code for application management.
This code is based on the Argo CD apiclient. You must replace
ClusterName,ClusterServer, andGitRepoURL.
go.mod configuration
When you import Argo CD Go packages into your Go project, you may encounter an "unknown revision v0.0.0" error when you download dependencies. This error occurs because Argo CD directly depends on Kubernetes packages whose go.mod files contain this v0.0.0 version.
You can resolve this issue by adding a `replace` directive. For more information, see the community documentation Importing Argo CD go packages. However, the required dependency versions in the `replace` directive vary based on the Argo CD version. You must set the versions of the Kubernetes packages in the `replace` directive to match the Argo CD version.
The demo in this topic uses the Go packages for Argo CD v2.9.3. Therefore, you must set all Kubernetes packages in the `replace` directive to v0.24.17, which corresponds to Argo CD v2.9.3. The following code provides a complete go.mod example:
References
For more information about the features of ACK One GitOps, see GitOps overview.
For a tutorial on how to use GitOps to publish multi-cluster applications, see GitOps Quick Start.