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

refactor(multicluster): Replace use of unstructured API with typed bindings for Link CR #13420

Merged
merged 8 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
9 changes: 6 additions & 3 deletions controller/gen/apis/link/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ type LinkSpec struct {
GatewayIdentity string `json:"gatewayIdentity,omitempty"`
ProbeSpec ProbeSpec `json:"probeSpec,omitempty"`
Selector metav1.LabelSelector `json:"selector,omitempty"`
RemoteDiscoverySelector metav1.LabelSelector `json:"remoteDiscoverySelector,omitempty"`
}

// ProbeSpec for gateway health probe
type ProbeSpec struct {
Path string `json:"path,omitempty"`
Port string `json:"port,omitempty"`
Period string `json:"period,omitempty"`
Path string `json:"path,omitempty"`
Port string `json:"port,omitempty"`
Period string `json:"period,omitempty"`
Timeout string `json:"timeout,omitempty"`
FailureThreshold string `json:"failureThreshold,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down

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

3 changes: 3 additions & 0 deletions controller/gen/apis/link/v1alpha2/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// +k8s:deepcopy-gen=package

package v1alpha2
48 changes: 48 additions & 0 deletions controller/gen/apis/link/v1alpha2/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package v1alpha2

import (
"github.com/linkerd/linkerd2/controller/gen/apis/link"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)

var (
// SchemeGroupVersion is the identifier for the API which includes the name
// of the group and the version of the API.
SchemeGroupVersion = schema.GroupVersion{
Group: link.GroupName,
Version: "v1alpha2",
}

// SchemeBuilder collects functions that add things to a scheme. It's to
// allow code to compile without explicitly referencing generated types.
// You should declare one in each package that will have generated deep
// copy or conversion functions.
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)

// AddToScheme applies all the stored functions to the scheme. A non-nil error
// indicates that one function failed and the attempt was abandoned.
AddToScheme = SchemeBuilder.AddToScheme
)

// Kind takes an unqualified kind and returns back a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}

// Resource takes an unqualified resource and returns a Group qualified
// GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

// Adds the list of known types to Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Link{},
&LinkList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
110 changes: 110 additions & 0 deletions controller/gen/apis/link/v1alpha2/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package v1alpha2

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +groupName=multicluster.linkerd.io

type Link struct {
// TypeMeta is the metadata for the resource, like kind and apiversion
metav1.TypeMeta `json:",inline"`

// ObjectMeta contains the metadata for the particular object, including
// things like...
// - name
// - namespace
// - self link
// - labels
// - ... etc ...
metav1.ObjectMeta `json:"metadata,omitempty"`

// Spec is the custom resource spec
Spec LinkSpec `json:"spec"`

// Status defines the current state of a Link
Status LinkStatus `json:"status,omitempty"`
}

// LinkSpec specifies a LinkSpec resource.
type LinkSpec struct {
TargetClusterName string `json:"targetClusterName,omitempty"`
TargetClusterDomain string `json:"targetClusterDomain,omitempty"`
TargetClusterLinkerdNamespace string `json:"targetClusterLinkerdNamespace,omitempty"`
ClusterCredentialsSecret string `json:"clusterCredentialsSecret,omitempty"`
GatewayAddress string `json:"gatewayAddress,omitempty"`
GatewayPort string `json:"gatewayPort,omitempty"`
GatewayIdentity string `json:"gatewayIdentity,omitempty"`
ProbeSpec ProbeSpec `json:"probeSpec,omitempty"`
Selector *metav1.LabelSelector `json:"selector,omitempty"`
RemoteDiscoverySelector *metav1.LabelSelector `json:"remoteDiscoverySelector,omitempty"`
FederatedServiceSelector *metav1.LabelSelector `json:"federatedServiceSelector,omitempty"`
}

// ProbeSpec for gateway health probe
type ProbeSpec struct {
Path string `json:"path,omitempty"`
Port string `json:"port,omitempty"`
Period string `json:"period,omitempty"`
Timeout string `json:"timeout,omitempty"`
FailureThreshold string `json:"failureThreshold,omitempty"`
}

// LinkStatus holds information about the status services mirrored with this
// Link.
type LinkStatus struct {
// +optional
MirrorServices []ServiceStatus `json:"mirrorServices,omitempty"`
// +optional
FederatedServices []ServiceStatus `json:"federatedServices,omitempty"`
}

type ServiceStatus struct {
Conditions []LinkCondition `json:"conditions,omitempty"`
ControllerName string `json:"controllerName,omitempty"`
RemoteRef ObjectRef `json:"remoteRef,omitempty"`
}

// LinkCondition represents the service state of an ExternalWorkload
type LinkCondition struct {
// Type of the condition
Type string `json:"type"`
// Status of the condition.
// Can be True, False, Unknown
Status string `json:"status"`
adleong marked this conversation as resolved.
Show resolved Hide resolved
// Last time an ExternalWorkload was probed for a condition.
// +optional
LastProbeTime metav1.Time `json:"lastProbeTime,omitempty"`
// Last time a condition transitioned from one status to another.
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// Unique one word reason in CamelCase that describes the reason for a
// transition.
// +optional
Reason string `json:"reason,omitempty"`
// Human readable message that describes details about last transition.
// +optional
Message string `json:"message"`
// LocalRef is a reference to the local mirror or federated service.
LocalRef ObjectRef `json:"localRef,omitempty"`
}

type ObjectRef struct {
Group string `json:"group,omitempty"`
Kind string `json:"kind,omitempty"`
Name string `json:"name,omitempty"`
Namespace string `json:"namespace,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// LinkList is a list of LinkList resources.
type LinkList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`

Items []Link `json:"items"`
}
Loading
Loading