In the process of developing a Custom Resource, importing other Custom Resource types such as Argo. #3982
-
I'm building a Custom Resource that automatically builds and deploys an app upon deployment. This Custom Resource depends on ArgoCD and needs to Get, Delete, and Create ArgoCD's CustomResource. I want to import ArgoCD's type struct and write code like the example below.
import (
argov1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
)
var argoProject argov1alpha1.AppProject
argoProject.Name = "simplecloud-" + project.Name
argoProject.Namespace = "argocd"
if err := r.Get(ctx, client.ObjectKey{Name: argoProject.Name, Namespace: argoProject.Namespace}, &argoProject); err != nil {
if client.IgnoreNotFound(err) != nil {
log.Info("ArgoCD project does not exist, creating it.")
argoProject.Spec.Description = "SimpleCloud Project"
argoProject.Spec.SourceRepos = []string{"*"}
destinations := []argov1alpha1.ApplicationDestination{}
destinations = append(destinations, argov1alpha1.ApplicationDestination{
Server: "*",
Namespace: namespaceName,
})
argoProject.Spec.Destinations = destinations
argoProject.Spec.ClusterResourceWhitelist = []metav1.GroupKind{
{
Group: "*",
Kind: "*",
},
}
argoProject.Spec.NamespaceResourceWhitelist = []metav1.GroupKind{
{
Group: "*",
Kind: "*",
},
}
if err := r.Create(ctx, &argoProject); err != nil {
return ctrl.Result{}, err
}
}
} AttemptsFollowing the official ArgoCD documentation, I installed the module and added dependencies. go get github.com/argoproj/argo-cd/[email protected] However, an error occurs during the
Questions
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
It's working fine when I run make run, and I'll comment if there are any issues. :) |
Beta Was this translation helpful? Give feedback.
-
The error messages you're encountering suggest a clash between the versions of dependencies your project uses and those required by the imported ArgoCD packages. The doc: https://book.kubebuilder.io/reference/using_an_external_type will help you out to know how to wrok with "external types", CRDs which are defined outside of your project like ArgoCD ones, in your kubebuilder project. So, I hope that answered your question. |
Beta Was this translation helpful? Give feedback.
Hi @study-eq-eat-drink
The error messages you're encountering suggest a clash between the versions of dependencies your project uses and those required by the imported ArgoCD packages.
The doc: https://book.kubebuilder.io/reference/using_an_external_type will help you out to know how to wrok with "external types", CRDs which are defined outside of your project like ArgoCD ones, in your kubebuilder project.
So, I hope that answered your question.
I am closing this one but if you still needing help please feel free to re-open.