Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
36 changes: 35 additions & 1 deletion pkg/core/manager/cluster/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
yaml "gopkg.in/yaml.v3"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -101,8 +102,41 @@
return nil, err
}
unstructuredCluster := &unstructured.Unstructured{Object: unstructuredMap}
return client.DynamicClient.Resource(clusterGVR).
clusterCreated, err := client.DynamicClient.Resource(clusterGVR).

Check failure on line 105 in pkg/core/manager/cluster/manager.go

View workflow job for this annotation

GitHub Actions / Golang Lint

ineffectual assignment to err (ineffassign)
Create(ctx, unstructuredCluster, metav1.CreateOptions{})

// Question: when use clusterapi.ClusterStatus, when use clusterv1beta1.ClusterStatus?
Copy link
Copy Markdown
Contributor Author

@jinjiaKarl jinjiaKarl Apr 4, 2025

Choose a reason for hiding this comment

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

I am kinda new to developing acustom apiserver and controller. Since there are internal api types and external (v1beta1) api types, can I ask which one to use in which situation?

In the syncer reconcile, it is all v1beta1 api types.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi! Karpor has two important features. One is resource insight and another is the proxy.

The api types in v1beta1 directory define the crd of special version (v1beta1), and we use it in syncing resource and insighting. The internal api types (such as pkg/kubernetes/apis/cluster/types.go) are used to proxy.

Copy link
Copy Markdown
Contributor Author

@jinjiaKarl jinjiaKarl Apr 5, 2025

Choose a reason for hiding this comment

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

Thanks for explaining!

cluster := &clusterv1beta1.Cluster{}
err = runtime.DefaultUnstructuredConverter.FromUnstructured(clusterCreated.Object, cluster)
if err != nil {
return nil, err
}

cluster = cluster.DeepCopy()

validatedCondition := metav1.Condition{
Type: clusterv1beta1.ValidatedCondition,
Status: metav1.ConditionTrue,
Reason: clusterv1beta1.ValidatedReason,
}
healthyCondition := metav1.Condition{
Type: clusterv1beta1.ClusterHealthyCondition,
Status: metav1.ConditionTrue,
Reason: clusterv1beta1.ClusterHealthyReason,
}

meta.SetStatusCondition(&cluster.Status.Conditions, validatedCondition)
meta.SetStatusCondition(&cluster.Status.Conditions, healthyCondition)
cluster.Status.APIServer = restConfig.Host
cluster.Status.Healthy = true
// TODO: Set cluster.Status.Version later in reconcile

unstructuredMap, err = runtime.DefaultUnstructuredConverter.ToUnstructured(cluster)
if err != nil {
return nil, err
}
unstructuredCluster = &unstructured.Unstructured{Object: unstructuredMap}
return client.DynamicClient.Resource(clusterGVR).Update(ctx, unstructuredCluster, metav1.UpdateOptions{})
}

// UpdateMetadata updates cluster by name with a full payload
Expand Down
19 changes: 18 additions & 1 deletion pkg/kubernetes/apis/cluster/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@
CredentialTypeOIDC CredentialType = "OIDC"
)

const (
ValidatedCondition = "Validated"
ClusterHealthyCondition = "ClusterHealthy"
)

const (
InvalidConfigReason = "InvalidConfig"
ValidatedReason = "Validated"

ClusterHealthyReason = "Healthy"
ClusterUnhealthyReason = "Unhealthy"
ClusterNotReachableReason = "NotReachable"
)

// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down Expand Up @@ -61,7 +75,10 @@
}

type ClusterStatus struct {
Healthy bool `json:"healthy,omitempty"`
Healthy bool `json:"healthy,omitempty"`
APIServer string `json:"apiserver,omitempty"`

Check failure on line 79 in pkg/kubernetes/apis/cluster/types.go

View workflow job for this annotation

GitHub Actions / Golang Lint

json(goCamel): got 'apiserver' want 'apiServer' (tagliatelle)
Version string `json:"version,omitempty"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

type ClusterAccess struct {
Expand Down
20 changes: 20 additions & 0 deletions pkg/kubernetes/apis/cluster/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@
CredentialTypeOIDC CredentialType = "OIDC"
)

const (
ValidatedCondition = "Validated"
ClusterHealthyCondition = "ClusterHealthy"
)

const (
InvalidConfigReason = "InvalidConfig"
ValidatedReason = "Validated"

ClusterHealthyReason = "Healthy"
ClusterUnhealthyReason = "Unhealthy"
ClusterNotReachableReason = "NotReachable"
)

// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down Expand Up @@ -64,6 +78,12 @@
type ClusterStatus struct {
// +optional
Healthy bool `json:"healthy,omitempty"`
// +optional
APIServer string `json:"apiserver,omitempty"`

Check failure on line 82 in pkg/kubernetes/apis/cluster/v1beta1/types.go

View workflow job for this annotation

GitHub Actions / Golang Lint

json(goCamel): got 'apiserver' want 'apiServer' (tagliatelle)
// +optional
Version string `json:"version,omitempty"`
// +optional
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

type ClusterAccess struct {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion pkg/kubernetes/apis/cluster/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion pkg/kubernetes/apis/cluster/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions pkg/kubernetes/generated/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading