diff --git a/pkg/apis/search/register.go b/pkg/apis/search/register.go index 610531dc..57952e0d 100644 --- a/pkg/apis/search/register.go +++ b/pkg/apis/search/register.go @@ -55,10 +55,10 @@ func addKnownTypes(scheme *runtime.Scheme) error { &TransformRuleList{}, &UniResource{}, &UniResourceList{}, - &UniresourceTopology{}, - &UniresourceTopologyList{}, - &UniresourceYAML{}, - &UniresourceYAMLList{}, + &UniResourceTopology{}, + &UniResourceTopologyList{}, + &UniResourceYAML{}, + &UniResourceYAMLList{}, ) return nil } diff --git a/pkg/apis/search/types.go b/pkg/apis/search/types.go index 50ec7485..b5e4ffdf 100644 --- a/pkg/apis/search/types.go +++ b/pkg/apis/search/types.go @@ -182,8 +182,16 @@ type ResourceSyncCondition struct { type UniResource struct { metav1.TypeMeta - Topology UniresourceTopology - YAML UniresourceYAML + Topology UniResourceTopology + YAML UniResourceYAML +} + +// +k8s:deepcopy-gen=true + +type UniresourceNode struct { + Identifier string + Parents []string + Children []string } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object @@ -195,25 +203,27 @@ type UniResourceList struct { // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type UniresourceTopology struct { +type UniResourceTopology struct { metav1.TypeMeta + Graph map[string]UniresourceNode } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type UniresourceTopologyList struct { +type UniResourceTopologyList struct { metav1.TypeMeta - Items []UniresourceTopology + Items []UniResourceTopology } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type UniresourceYAML struct { +type UniResourceYAML struct { metav1.TypeMeta + YAMLString string } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type UniresourceYAMLList struct { +type UniResourceYAMLList struct { metav1.TypeMeta - Items []UniresourceYAML + Items []UniResourceYAML } diff --git a/pkg/apis/search/v1beta1/register.go b/pkg/apis/search/v1beta1/register.go index 58258eae..3fa2b93e 100644 --- a/pkg/apis/search/v1beta1/register.go +++ b/pkg/apis/search/v1beta1/register.go @@ -57,10 +57,10 @@ func addKnownTypes(scheme *runtime.Scheme) error { &TransformRuleList{}, &UniResource{}, &UniResourceList{}, - &UniresourceTopology{}, - &UniresourceTopologyList{}, - &UniresourceYAML{}, - &UniresourceYAMLList{}, + &UniResourceTopology{}, + &UniResourceTopologyList{}, + &UniResourceYAML{}, + &UniResourceYAMLList{}, ) metav1.AddToGroupVersion(scheme, SchemeGroupVersion) return nil diff --git a/pkg/apis/search/v1beta1/types.go b/pkg/apis/search/v1beta1/types.go index f442da78..a70c5c8a 100644 --- a/pkg/apis/search/v1beta1/types.go +++ b/pkg/apis/search/v1beta1/types.go @@ -219,8 +219,8 @@ type ResourceSyncCondition struct { type UniResource struct { metav1.TypeMeta `json:",inline"` - Topology UniresourceTopology - YAML UniresourceYAML + Topology UniResourceTopology + YAML UniResourceYAML } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object @@ -230,27 +230,37 @@ type UniResourceList struct { Items []runtime.RawExtension `json:"items"` } +// +k8s:deepcopy-gen=true + +type UniresourceNode struct { + Identifier string + Parents []string + Children []string +} + // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type UniresourceTopology struct { +type UniResourceTopology struct { metav1.TypeMeta + Graph map[string]UniresourceNode } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type UniresourceTopologyList struct { +type UniResourceTopologyList struct { metav1.TypeMeta - Items []UniresourceTopology + Items []UniResourceTopology } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type UniresourceYAML struct { +type UniResourceYAML struct { metav1.TypeMeta + YAMLString string } // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object -type UniresourceYAMLList struct { +type UniResourceYAMLList struct { metav1.TypeMeta - Items []UniresourceYAML + Items []UniResourceYAML } diff --git a/pkg/apis/search/v1beta1/zz_generated.conversion.go b/pkg/apis/search/v1beta1/zz_generated.conversion.go index ce85811d..02504d51 100644 --- a/pkg/apis/search/v1beta1/zz_generated.conversion.go +++ b/pkg/apis/search/v1beta1/zz_generated.conversion.go @@ -207,43 +207,53 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*UniresourceTopology)(nil), (*search.UniresourceTopology)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_UniresourceTopology_To_search_UniresourceTopology(a.(*UniresourceTopology), b.(*search.UniresourceTopology), scope) + if err := s.AddGeneratedConversionFunc((*UniResourceTopology)(nil), (*search.UniResourceTopology)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_UniResourceTopology_To_search_UniResourceTopology(a.(*UniResourceTopology), b.(*search.UniResourceTopology), scope) }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*search.UniresourceTopology)(nil), (*UniresourceTopology)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_search_UniresourceTopology_To_v1beta1_UniresourceTopology(a.(*search.UniresourceTopology), b.(*UniresourceTopology), scope) + if err := s.AddGeneratedConversionFunc((*search.UniResourceTopology)(nil), (*UniResourceTopology)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_search_UniResourceTopology_To_v1beta1_UniResourceTopology(a.(*search.UniResourceTopology), b.(*UniResourceTopology), scope) }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*UniresourceTopologyList)(nil), (*search.UniresourceTopologyList)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_UniresourceTopologyList_To_search_UniresourceTopologyList(a.(*UniresourceTopologyList), b.(*search.UniresourceTopologyList), scope) + if err := s.AddGeneratedConversionFunc((*UniResourceTopologyList)(nil), (*search.UniResourceTopologyList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_UniResourceTopologyList_To_search_UniResourceTopologyList(a.(*UniResourceTopologyList), b.(*search.UniResourceTopologyList), scope) }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*search.UniresourceTopologyList)(nil), (*UniresourceTopologyList)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_search_UniresourceTopologyList_To_v1beta1_UniresourceTopologyList(a.(*search.UniresourceTopologyList), b.(*UniresourceTopologyList), scope) + if err := s.AddGeneratedConversionFunc((*search.UniResourceTopologyList)(nil), (*UniResourceTopologyList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_search_UniResourceTopologyList_To_v1beta1_UniResourceTopologyList(a.(*search.UniResourceTopologyList), b.(*UniResourceTopologyList), scope) }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*UniresourceYAML)(nil), (*search.UniresourceYAML)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_UniresourceYAML_To_search_UniresourceYAML(a.(*UniresourceYAML), b.(*search.UniresourceYAML), scope) + if err := s.AddGeneratedConversionFunc((*UniResourceYAML)(nil), (*search.UniResourceYAML)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_UniResourceYAML_To_search_UniResourceYAML(a.(*UniResourceYAML), b.(*search.UniResourceYAML), scope) }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*search.UniresourceYAML)(nil), (*UniresourceYAML)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_search_UniresourceYAML_To_v1beta1_UniresourceYAML(a.(*search.UniresourceYAML), b.(*UniresourceYAML), scope) + if err := s.AddGeneratedConversionFunc((*search.UniResourceYAML)(nil), (*UniResourceYAML)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_search_UniResourceYAML_To_v1beta1_UniResourceYAML(a.(*search.UniResourceYAML), b.(*UniResourceYAML), scope) }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*UniresourceYAMLList)(nil), (*search.UniresourceYAMLList)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_UniresourceYAMLList_To_search_UniresourceYAMLList(a.(*UniresourceYAMLList), b.(*search.UniresourceYAMLList), scope) + if err := s.AddGeneratedConversionFunc((*UniResourceYAMLList)(nil), (*search.UniResourceYAMLList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_UniResourceYAMLList_To_search_UniResourceYAMLList(a.(*UniResourceYAMLList), b.(*search.UniResourceYAMLList), scope) }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*search.UniresourceYAMLList)(nil), (*UniresourceYAMLList)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_search_UniresourceYAMLList_To_v1beta1_UniresourceYAMLList(a.(*search.UniresourceYAMLList), b.(*UniresourceYAMLList), scope) + if err := s.AddGeneratedConversionFunc((*search.UniResourceYAMLList)(nil), (*UniResourceYAMLList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_search_UniResourceYAMLList_To_v1beta1_UniResourceYAMLList(a.(*search.UniResourceYAMLList), b.(*UniResourceYAMLList), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*UniresourceNode)(nil), (*search.UniresourceNode)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_UniresourceNode_To_search_UniresourceNode(a.(*UniresourceNode), b.(*search.UniresourceNode), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*search.UniresourceNode)(nil), (*UniresourceNode)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_search_UniresourceNode_To_v1beta1_UniresourceNode(a.(*search.UniresourceNode), b.(*UniresourceNode), scope) }); err != nil { return err } @@ -627,10 +637,10 @@ func Convert_search_TransformRuleSpec_To_v1beta1_TransformRuleSpec(in *search.Tr } func autoConvert_v1beta1_UniResource_To_search_UniResource(in *UniResource, out *search.UniResource, s conversion.Scope) error { - if err := Convert_v1beta1_UniresourceTopology_To_search_UniresourceTopology(&in.Topology, &out.Topology, s); err != nil { + if err := Convert_v1beta1_UniResourceTopology_To_search_UniResourceTopology(&in.Topology, &out.Topology, s); err != nil { return err } - if err := Convert_v1beta1_UniresourceYAML_To_search_UniresourceYAML(&in.YAML, &out.YAML, s); err != nil { + if err := Convert_v1beta1_UniResourceYAML_To_search_UniResourceYAML(&in.YAML, &out.YAML, s); err != nil { return err } return nil @@ -642,10 +652,10 @@ func Convert_v1beta1_UniResource_To_search_UniResource(in *UniResource, out *sea } func autoConvert_search_UniResource_To_v1beta1_UniResource(in *search.UniResource, out *UniResource, s conversion.Scope) error { - if err := Convert_search_UniresourceTopology_To_v1beta1_UniresourceTopology(&in.Topology, &out.Topology, s); err != nil { + if err := Convert_search_UniResourceTopology_To_v1beta1_UniResourceTopology(&in.Topology, &out.Topology, s); err != nil { return err } - if err := Convert_search_UniresourceYAML_To_v1beta1_UniresourceYAML(&in.YAML, &out.YAML, s); err != nil { + if err := Convert_search_UniResourceYAML_To_v1beta1_UniResourceYAML(&in.YAML, &out.YAML, s); err != nil { return err } return nil @@ -696,78 +706,106 @@ func Convert_search_UniResourceList_To_v1beta1_UniResourceList(in *search.UniRes return autoConvert_search_UniResourceList_To_v1beta1_UniResourceList(in, out, s) } -func autoConvert_v1beta1_UniresourceTopology_To_search_UniresourceTopology(in *UniresourceTopology, out *search.UniresourceTopology, s conversion.Scope) error { +func autoConvert_v1beta1_UniResourceTopology_To_search_UniResourceTopology(in *UniResourceTopology, out *search.UniResourceTopology, s conversion.Scope) error { + out.Graph = *(*map[string]search.UniresourceNode)(unsafe.Pointer(&in.Graph)) + return nil +} + +// Convert_v1beta1_UniResourceTopology_To_search_UniResourceTopology is an autogenerated conversion function. +func Convert_v1beta1_UniResourceTopology_To_search_UniResourceTopology(in *UniResourceTopology, out *search.UniResourceTopology, s conversion.Scope) error { + return autoConvert_v1beta1_UniResourceTopology_To_search_UniResourceTopology(in, out, s) +} + +func autoConvert_search_UniResourceTopology_To_v1beta1_UniResourceTopology(in *search.UniResourceTopology, out *UniResourceTopology, s conversion.Scope) error { + out.Graph = *(*map[string]UniresourceNode)(unsafe.Pointer(&in.Graph)) + return nil +} + +// Convert_search_UniResourceTopology_To_v1beta1_UniResourceTopology is an autogenerated conversion function. +func Convert_search_UniResourceTopology_To_v1beta1_UniResourceTopology(in *search.UniResourceTopology, out *UniResourceTopology, s conversion.Scope) error { + return autoConvert_search_UniResourceTopology_To_v1beta1_UniResourceTopology(in, out, s) +} + +func autoConvert_v1beta1_UniResourceTopologyList_To_search_UniResourceTopologyList(in *UniResourceTopologyList, out *search.UniResourceTopologyList, s conversion.Scope) error { + out.Items = *(*[]search.UniResourceTopology)(unsafe.Pointer(&in.Items)) return nil } -// Convert_v1beta1_UniresourceTopology_To_search_UniresourceTopology is an autogenerated conversion function. -func Convert_v1beta1_UniresourceTopology_To_search_UniresourceTopology(in *UniresourceTopology, out *search.UniresourceTopology, s conversion.Scope) error { - return autoConvert_v1beta1_UniresourceTopology_To_search_UniresourceTopology(in, out, s) +// Convert_v1beta1_UniResourceTopologyList_To_search_UniResourceTopologyList is an autogenerated conversion function. +func Convert_v1beta1_UniResourceTopologyList_To_search_UniResourceTopologyList(in *UniResourceTopologyList, out *search.UniResourceTopologyList, s conversion.Scope) error { + return autoConvert_v1beta1_UniResourceTopologyList_To_search_UniResourceTopologyList(in, out, s) } -func autoConvert_search_UniresourceTopology_To_v1beta1_UniresourceTopology(in *search.UniresourceTopology, out *UniresourceTopology, s conversion.Scope) error { +func autoConvert_search_UniResourceTopologyList_To_v1beta1_UniResourceTopologyList(in *search.UniResourceTopologyList, out *UniResourceTopologyList, s conversion.Scope) error { + out.Items = *(*[]UniResourceTopology)(unsafe.Pointer(&in.Items)) return nil } -// Convert_search_UniresourceTopology_To_v1beta1_UniresourceTopology is an autogenerated conversion function. -func Convert_search_UniresourceTopology_To_v1beta1_UniresourceTopology(in *search.UniresourceTopology, out *UniresourceTopology, s conversion.Scope) error { - return autoConvert_search_UniresourceTopology_To_v1beta1_UniresourceTopology(in, out, s) +// Convert_search_UniResourceTopologyList_To_v1beta1_UniResourceTopologyList is an autogenerated conversion function. +func Convert_search_UniResourceTopologyList_To_v1beta1_UniResourceTopologyList(in *search.UniResourceTopologyList, out *UniResourceTopologyList, s conversion.Scope) error { + return autoConvert_search_UniResourceTopologyList_To_v1beta1_UniResourceTopologyList(in, out, s) } -func autoConvert_v1beta1_UniresourceTopologyList_To_search_UniresourceTopologyList(in *UniresourceTopologyList, out *search.UniresourceTopologyList, s conversion.Scope) error { - out.Items = *(*[]search.UniresourceTopology)(unsafe.Pointer(&in.Items)) +func autoConvert_v1beta1_UniResourceYAML_To_search_UniResourceYAML(in *UniResourceYAML, out *search.UniResourceYAML, s conversion.Scope) error { + out.YAMLString = in.YAMLString return nil } -// Convert_v1beta1_UniresourceTopologyList_To_search_UniresourceTopologyList is an autogenerated conversion function. -func Convert_v1beta1_UniresourceTopologyList_To_search_UniresourceTopologyList(in *UniresourceTopologyList, out *search.UniresourceTopologyList, s conversion.Scope) error { - return autoConvert_v1beta1_UniresourceTopologyList_To_search_UniresourceTopologyList(in, out, s) +// Convert_v1beta1_UniResourceYAML_To_search_UniResourceYAML is an autogenerated conversion function. +func Convert_v1beta1_UniResourceYAML_To_search_UniResourceYAML(in *UniResourceYAML, out *search.UniResourceYAML, s conversion.Scope) error { + return autoConvert_v1beta1_UniResourceYAML_To_search_UniResourceYAML(in, out, s) } -func autoConvert_search_UniresourceTopologyList_To_v1beta1_UniresourceTopologyList(in *search.UniresourceTopologyList, out *UniresourceTopologyList, s conversion.Scope) error { - out.Items = *(*[]UniresourceTopology)(unsafe.Pointer(&in.Items)) +func autoConvert_search_UniResourceYAML_To_v1beta1_UniResourceYAML(in *search.UniResourceYAML, out *UniResourceYAML, s conversion.Scope) error { + out.YAMLString = in.YAMLString return nil } -// Convert_search_UniresourceTopologyList_To_v1beta1_UniresourceTopologyList is an autogenerated conversion function. -func Convert_search_UniresourceTopologyList_To_v1beta1_UniresourceTopologyList(in *search.UniresourceTopologyList, out *UniresourceTopologyList, s conversion.Scope) error { - return autoConvert_search_UniresourceTopologyList_To_v1beta1_UniresourceTopologyList(in, out, s) +// Convert_search_UniResourceYAML_To_v1beta1_UniResourceYAML is an autogenerated conversion function. +func Convert_search_UniResourceYAML_To_v1beta1_UniResourceYAML(in *search.UniResourceYAML, out *UniResourceYAML, s conversion.Scope) error { + return autoConvert_search_UniResourceYAML_To_v1beta1_UniResourceYAML(in, out, s) } -func autoConvert_v1beta1_UniresourceYAML_To_search_UniresourceYAML(in *UniresourceYAML, out *search.UniresourceYAML, s conversion.Scope) error { +func autoConvert_v1beta1_UniResourceYAMLList_To_search_UniResourceYAMLList(in *UniResourceYAMLList, out *search.UniResourceYAMLList, s conversion.Scope) error { + out.Items = *(*[]search.UniResourceYAML)(unsafe.Pointer(&in.Items)) return nil } -// Convert_v1beta1_UniresourceYAML_To_search_UniresourceYAML is an autogenerated conversion function. -func Convert_v1beta1_UniresourceYAML_To_search_UniresourceYAML(in *UniresourceYAML, out *search.UniresourceYAML, s conversion.Scope) error { - return autoConvert_v1beta1_UniresourceYAML_To_search_UniresourceYAML(in, out, s) +// Convert_v1beta1_UniResourceYAMLList_To_search_UniResourceYAMLList is an autogenerated conversion function. +func Convert_v1beta1_UniResourceYAMLList_To_search_UniResourceYAMLList(in *UniResourceYAMLList, out *search.UniResourceYAMLList, s conversion.Scope) error { + return autoConvert_v1beta1_UniResourceYAMLList_To_search_UniResourceYAMLList(in, out, s) } -func autoConvert_search_UniresourceYAML_To_v1beta1_UniresourceYAML(in *search.UniresourceYAML, out *UniresourceYAML, s conversion.Scope) error { +func autoConvert_search_UniResourceYAMLList_To_v1beta1_UniResourceYAMLList(in *search.UniResourceYAMLList, out *UniResourceYAMLList, s conversion.Scope) error { + out.Items = *(*[]UniResourceYAML)(unsafe.Pointer(&in.Items)) return nil } -// Convert_search_UniresourceYAML_To_v1beta1_UniresourceYAML is an autogenerated conversion function. -func Convert_search_UniresourceYAML_To_v1beta1_UniresourceYAML(in *search.UniresourceYAML, out *UniresourceYAML, s conversion.Scope) error { - return autoConvert_search_UniresourceYAML_To_v1beta1_UniresourceYAML(in, out, s) +// Convert_search_UniResourceYAMLList_To_v1beta1_UniResourceYAMLList is an autogenerated conversion function. +func Convert_search_UniResourceYAMLList_To_v1beta1_UniResourceYAMLList(in *search.UniResourceYAMLList, out *UniResourceYAMLList, s conversion.Scope) error { + return autoConvert_search_UniResourceYAMLList_To_v1beta1_UniResourceYAMLList(in, out, s) } -func autoConvert_v1beta1_UniresourceYAMLList_To_search_UniresourceYAMLList(in *UniresourceYAMLList, out *search.UniresourceYAMLList, s conversion.Scope) error { - out.Items = *(*[]search.UniresourceYAML)(unsafe.Pointer(&in.Items)) +func autoConvert_v1beta1_UniresourceNode_To_search_UniresourceNode(in *UniresourceNode, out *search.UniresourceNode, s conversion.Scope) error { + out.Identifier = in.Identifier + out.Parents = *(*[]string)(unsafe.Pointer(&in.Parents)) + out.Children = *(*[]string)(unsafe.Pointer(&in.Children)) return nil } -// Convert_v1beta1_UniresourceYAMLList_To_search_UniresourceYAMLList is an autogenerated conversion function. -func Convert_v1beta1_UniresourceYAMLList_To_search_UniresourceYAMLList(in *UniresourceYAMLList, out *search.UniresourceYAMLList, s conversion.Scope) error { - return autoConvert_v1beta1_UniresourceYAMLList_To_search_UniresourceYAMLList(in, out, s) +// Convert_v1beta1_UniresourceNode_To_search_UniresourceNode is an autogenerated conversion function. +func Convert_v1beta1_UniresourceNode_To_search_UniresourceNode(in *UniresourceNode, out *search.UniresourceNode, s conversion.Scope) error { + return autoConvert_v1beta1_UniresourceNode_To_search_UniresourceNode(in, out, s) } -func autoConvert_search_UniresourceYAMLList_To_v1beta1_UniresourceYAMLList(in *search.UniresourceYAMLList, out *UniresourceYAMLList, s conversion.Scope) error { - out.Items = *(*[]UniresourceYAML)(unsafe.Pointer(&in.Items)) +func autoConvert_search_UniresourceNode_To_v1beta1_UniresourceNode(in *search.UniresourceNode, out *UniresourceNode, s conversion.Scope) error { + out.Identifier = in.Identifier + out.Parents = *(*[]string)(unsafe.Pointer(&in.Parents)) + out.Children = *(*[]string)(unsafe.Pointer(&in.Children)) return nil } -// Convert_search_UniresourceYAMLList_To_v1beta1_UniresourceYAMLList is an autogenerated conversion function. -func Convert_search_UniresourceYAMLList_To_v1beta1_UniresourceYAMLList(in *search.UniresourceYAMLList, out *UniresourceYAMLList, s conversion.Scope) error { - return autoConvert_search_UniresourceYAMLList_To_v1beta1_UniresourceYAMLList(in, out, s) +// Convert_search_UniresourceNode_To_v1beta1_UniresourceNode is an autogenerated conversion function. +func Convert_search_UniresourceNode_To_v1beta1_UniresourceNode(in *search.UniresourceNode, out *UniresourceNode, s conversion.Scope) error { + return autoConvert_search_UniresourceNode_To_v1beta1_UniresourceNode(in, out, s) } diff --git a/pkg/apis/search/v1beta1/zz_generated.deepcopy.go b/pkg/apis/search/v1beta1/zz_generated.deepcopy.go index 7c30ba65..33e1efd2 100644 --- a/pkg/apis/search/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/search/v1beta1/zz_generated.deepcopy.go @@ -416,7 +416,7 @@ func (in *TransformRuleSpec) DeepCopy() *TransformRuleSpec { func (in *UniResource) DeepCopyInto(out *UniResource) { *out = *in out.TypeMeta = in.TypeMeta - out.Topology = in.Topology + in.Topology.DeepCopyInto(&out.Topology) out.YAML = in.YAML return } @@ -472,24 +472,31 @@ func (in *UniResourceList) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *UniresourceTopology) DeepCopyInto(out *UniresourceTopology) { +func (in *UniResourceTopology) DeepCopyInto(out *UniResourceTopology) { *out = *in out.TypeMeta = in.TypeMeta + if in.Graph != nil { + in, out := &in.Graph, &out.Graph + *out = make(map[string]UniresourceNode, len(*in)) + for key, val := range *in { + (*out)[key] = *val.DeepCopy() + } + } return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UniresourceTopology. -func (in *UniresourceTopology) DeepCopy() *UniresourceTopology { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UniResourceTopology. +func (in *UniResourceTopology) DeepCopy() *UniResourceTopology { if in == nil { return nil } - out := new(UniresourceTopology) + out := new(UniResourceTopology) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *UniresourceTopology) DeepCopyObject() runtime.Object { +func (in *UniResourceTopology) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -497,29 +504,31 @@ func (in *UniresourceTopology) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *UniresourceTopologyList) DeepCopyInto(out *UniresourceTopologyList) { +func (in *UniResourceTopologyList) DeepCopyInto(out *UniResourceTopologyList) { *out = *in out.TypeMeta = in.TypeMeta if in.Items != nil { in, out := &in.Items, &out.Items - *out = make([]UniresourceTopology, len(*in)) - copy(*out, *in) + *out = make([]UniResourceTopology, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UniresourceTopologyList. -func (in *UniresourceTopologyList) DeepCopy() *UniresourceTopologyList { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UniResourceTopologyList. +func (in *UniResourceTopologyList) DeepCopy() *UniResourceTopologyList { if in == nil { return nil } - out := new(UniresourceTopologyList) + out := new(UniResourceTopologyList) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *UniresourceTopologyList) DeepCopyObject() runtime.Object { +func (in *UniResourceTopologyList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -527,24 +536,24 @@ func (in *UniresourceTopologyList) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *UniresourceYAML) DeepCopyInto(out *UniresourceYAML) { +func (in *UniResourceYAML) DeepCopyInto(out *UniResourceYAML) { *out = *in out.TypeMeta = in.TypeMeta return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UniresourceYAML. -func (in *UniresourceYAML) DeepCopy() *UniresourceYAML { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UniResourceYAML. +func (in *UniResourceYAML) DeepCopy() *UniResourceYAML { if in == nil { return nil } - out := new(UniresourceYAML) + out := new(UniResourceYAML) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *UniresourceYAML) DeepCopyObject() runtime.Object { +func (in *UniResourceYAML) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -552,31 +561,57 @@ func (in *UniresourceYAML) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *UniresourceYAMLList) DeepCopyInto(out *UniresourceYAMLList) { +func (in *UniResourceYAMLList) DeepCopyInto(out *UniResourceYAMLList) { *out = *in out.TypeMeta = in.TypeMeta if in.Items != nil { in, out := &in.Items, &out.Items - *out = make([]UniresourceYAML, len(*in)) + *out = make([]UniResourceYAML, len(*in)) copy(*out, *in) } return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UniresourceYAMLList. -func (in *UniresourceYAMLList) DeepCopy() *UniresourceYAMLList { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UniResourceYAMLList. +func (in *UniResourceYAMLList) DeepCopy() *UniResourceYAMLList { if in == nil { return nil } - out := new(UniresourceYAMLList) + out := new(UniResourceYAMLList) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *UniresourceYAMLList) DeepCopyObject() runtime.Object { +func (in *UniResourceYAMLList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } return nil } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *UniresourceNode) DeepCopyInto(out *UniresourceNode) { + *out = *in + if in.Parents != nil { + in, out := &in.Parents, &out.Parents + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.Children != nil { + in, out := &in.Children, &out.Children + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UniresourceNode. +func (in *UniresourceNode) DeepCopy() *UniresourceNode { + if in == nil { + return nil + } + out := new(UniresourceNode) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/apis/search/zz_generated.deepcopy.go b/pkg/apis/search/zz_generated.deepcopy.go index b93a1d1a..d034fcb3 100644 --- a/pkg/apis/search/zz_generated.deepcopy.go +++ b/pkg/apis/search/zz_generated.deepcopy.go @@ -416,7 +416,7 @@ func (in *TransformRuleSpec) DeepCopy() *TransformRuleSpec { func (in *UniResource) DeepCopyInto(out *UniResource) { *out = *in out.TypeMeta = in.TypeMeta - out.Topology = in.Topology + in.Topology.DeepCopyInto(&out.Topology) out.YAML = in.YAML return } @@ -474,24 +474,31 @@ func (in *UniResourceList) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *UniresourceTopology) DeepCopyInto(out *UniresourceTopology) { +func (in *UniResourceTopology) DeepCopyInto(out *UniResourceTopology) { *out = *in out.TypeMeta = in.TypeMeta + if in.Graph != nil { + in, out := &in.Graph, &out.Graph + *out = make(map[string]UniresourceNode, len(*in)) + for key, val := range *in { + (*out)[key] = *val.DeepCopy() + } + } return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UniresourceTopology. -func (in *UniresourceTopology) DeepCopy() *UniresourceTopology { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UniResourceTopology. +func (in *UniResourceTopology) DeepCopy() *UniResourceTopology { if in == nil { return nil } - out := new(UniresourceTopology) + out := new(UniResourceTopology) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *UniresourceTopology) DeepCopyObject() runtime.Object { +func (in *UniResourceTopology) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -499,29 +506,31 @@ func (in *UniresourceTopology) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *UniresourceTopologyList) DeepCopyInto(out *UniresourceTopologyList) { +func (in *UniResourceTopologyList) DeepCopyInto(out *UniResourceTopologyList) { *out = *in out.TypeMeta = in.TypeMeta if in.Items != nil { in, out := &in.Items, &out.Items - *out = make([]UniresourceTopology, len(*in)) - copy(*out, *in) + *out = make([]UniResourceTopology, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UniresourceTopologyList. -func (in *UniresourceTopologyList) DeepCopy() *UniresourceTopologyList { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UniResourceTopologyList. +func (in *UniResourceTopologyList) DeepCopy() *UniResourceTopologyList { if in == nil { return nil } - out := new(UniresourceTopologyList) + out := new(UniResourceTopologyList) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *UniresourceTopologyList) DeepCopyObject() runtime.Object { +func (in *UniResourceTopologyList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -529,24 +538,24 @@ func (in *UniresourceTopologyList) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *UniresourceYAML) DeepCopyInto(out *UniresourceYAML) { +func (in *UniResourceYAML) DeepCopyInto(out *UniResourceYAML) { *out = *in out.TypeMeta = in.TypeMeta return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UniresourceYAML. -func (in *UniresourceYAML) DeepCopy() *UniresourceYAML { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UniResourceYAML. +func (in *UniResourceYAML) DeepCopy() *UniResourceYAML { if in == nil { return nil } - out := new(UniresourceYAML) + out := new(UniResourceYAML) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *UniresourceYAML) DeepCopyObject() runtime.Object { +func (in *UniResourceYAML) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -554,31 +563,57 @@ func (in *UniresourceYAML) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *UniresourceYAMLList) DeepCopyInto(out *UniresourceYAMLList) { +func (in *UniResourceYAMLList) DeepCopyInto(out *UniResourceYAMLList) { *out = *in out.TypeMeta = in.TypeMeta if in.Items != nil { in, out := &in.Items, &out.Items - *out = make([]UniresourceYAML, len(*in)) + *out = make([]UniResourceYAML, len(*in)) copy(*out, *in) } return } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UniresourceYAMLList. -func (in *UniresourceYAMLList) DeepCopy() *UniresourceYAMLList { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UniResourceYAMLList. +func (in *UniResourceYAMLList) DeepCopy() *UniResourceYAMLList { if in == nil { return nil } - out := new(UniresourceYAMLList) + out := new(UniResourceYAMLList) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *UniresourceYAMLList) DeepCopyObject() runtime.Object { +func (in *UniResourceYAMLList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } return nil } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *UniresourceNode) DeepCopyInto(out *UniresourceNode) { + *out = *in + if in.Parents != nil { + in, out := &in.Parents, &out.Parents + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.Children != nil { + in, out := &in.Children, &out.Children + *out = make([]string, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new UniresourceNode. +func (in *UniresourceNode) DeepCopy() *UniresourceNode { + if in == nil { + return nil + } + out := new(UniresourceNode) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index bc3d4865..6a662725 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -57,10 +57,11 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/KusionStack/karbour/pkg/apis/search/v1beta1.TransformRuleSpec": schema_pkg_apis_search_v1beta1_TransformRuleSpec(ref), "github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniResource": schema_pkg_apis_search_v1beta1_UniResource(ref), "github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniResourceList": schema_pkg_apis_search_v1beta1_UniResourceList(ref), - "github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniresourceTopology": schema_pkg_apis_search_v1beta1_UniresourceTopology(ref), - "github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniresourceTopologyList": schema_pkg_apis_search_v1beta1_UniresourceTopologyList(ref), - "github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniresourceYAML": schema_pkg_apis_search_v1beta1_UniresourceYAML(ref), - "github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniresourceYAMLList": schema_pkg_apis_search_v1beta1_UniresourceYAMLList(ref), + "github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniResourceTopology": schema_pkg_apis_search_v1beta1_UniResourceTopology(ref), + "github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniResourceTopologyList": schema_pkg_apis_search_v1beta1_UniResourceTopologyList(ref), + "github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniResourceYAML": schema_pkg_apis_search_v1beta1_UniResourceYAML(ref), + "github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniResourceYAMLList": schema_pkg_apis_search_v1beta1_UniResourceYAMLList(ref), + "github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniresourceNode": schema_pkg_apis_search_v1beta1_UniresourceNode(ref), "k8s.io/apimachinery/pkg/apis/meta/v1.APIGroup": schema_pkg_apis_meta_v1_APIGroup(ref), "k8s.io/apimachinery/pkg/apis/meta/v1.APIGroupList": schema_pkg_apis_meta_v1_APIGroupList(ref), "k8s.io/apimachinery/pkg/apis/meta/v1.APIResource": schema_pkg_apis_meta_v1_APIResource(ref), @@ -1118,13 +1119,13 @@ func schema_pkg_apis_search_v1beta1_UniResource(ref common.ReferenceCallback) co "Topology": { SchemaProps: spec.SchemaProps{ Default: map[string]interface{}{}, - Ref: ref("github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniresourceTopology"), + Ref: ref("github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniResourceTopology"), }, }, "YAML": { SchemaProps: spec.SchemaProps{ Default: map[string]interface{}{}, - Ref: ref("github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniresourceYAML"), + Ref: ref("github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniResourceYAML"), }, }, }, @@ -1132,7 +1133,7 @@ func schema_pkg_apis_search_v1beta1_UniResource(ref common.ReferenceCallback) co }, }, Dependencies: []string{ - "github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniresourceTopology", "github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniresourceYAML"}, + "github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniResourceTopology", "github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniResourceYAML"}, } } @@ -1178,7 +1179,7 @@ func schema_pkg_apis_search_v1beta1_UniResourceList(ref common.ReferenceCallback } } -func schema_pkg_apis_search_v1beta1_UniresourceTopology(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema_pkg_apis_search_v1beta1_UniResourceTopology(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ @@ -1190,16 +1191,30 @@ func schema_pkg_apis_search_v1beta1_UniresourceTopology(ref common.ReferenceCall Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.TypeMeta"), }, }, + "Graph": { + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniresourceNode"), + }, + }, + }, + }, + }, }, - Required: []string{"TypeMeta"}, + Required: []string{"TypeMeta", "Graph"}, }, }, Dependencies: []string{ - "k8s.io/apimachinery/pkg/apis/meta/v1.TypeMeta"}, + "github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniresourceNode", "k8s.io/apimachinery/pkg/apis/meta/v1.TypeMeta"}, } } -func schema_pkg_apis_search_v1beta1_UniresourceTopologyList(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema_pkg_apis_search_v1beta1_UniResourceTopologyList(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ @@ -1218,7 +1233,7 @@ func schema_pkg_apis_search_v1beta1_UniresourceTopologyList(ref common.Reference Schema: &spec.Schema{ SchemaProps: spec.SchemaProps{ Default: map[string]interface{}{}, - Ref: ref("github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniresourceTopology"), + Ref: ref("github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniResourceTopology"), }, }, }, @@ -1229,11 +1244,11 @@ func schema_pkg_apis_search_v1beta1_UniresourceTopologyList(ref common.Reference }, }, Dependencies: []string{ - "github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniresourceTopology", "k8s.io/apimachinery/pkg/apis/meta/v1.TypeMeta"}, + "github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniResourceTopology", "k8s.io/apimachinery/pkg/apis/meta/v1.TypeMeta"}, } } -func schema_pkg_apis_search_v1beta1_UniresourceYAML(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema_pkg_apis_search_v1beta1_UniResourceYAML(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ @@ -1245,8 +1260,15 @@ func schema_pkg_apis_search_v1beta1_UniresourceYAML(ref common.ReferenceCallback Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.TypeMeta"), }, }, + "YAMLString": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, }, - Required: []string{"TypeMeta"}, + Required: []string{"TypeMeta", "YAMLString"}, }, }, Dependencies: []string{ @@ -1254,7 +1276,7 @@ func schema_pkg_apis_search_v1beta1_UniresourceYAML(ref common.ReferenceCallback } } -func schema_pkg_apis_search_v1beta1_UniresourceYAMLList(ref common.ReferenceCallback) common.OpenAPIDefinition { +func schema_pkg_apis_search_v1beta1_UniResourceYAMLList(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ @@ -1273,7 +1295,7 @@ func schema_pkg_apis_search_v1beta1_UniresourceYAMLList(ref common.ReferenceCall Schema: &spec.Schema{ SchemaProps: spec.SchemaProps{ Default: map[string]interface{}{}, - Ref: ref("github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniresourceYAML"), + Ref: ref("github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniResourceYAML"), }, }, }, @@ -1284,7 +1306,55 @@ func schema_pkg_apis_search_v1beta1_UniresourceYAMLList(ref common.ReferenceCall }, }, Dependencies: []string{ - "github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniresourceYAML", "k8s.io/apimachinery/pkg/apis/meta/v1.TypeMeta"}, + "github.com/KusionStack/karbour/pkg/apis/search/v1beta1.UniResourceYAML", "k8s.io/apimachinery/pkg/apis/meta/v1.TypeMeta"}, + } +} + +func schema_pkg_apis_search_v1beta1_UniresourceNode(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "Identifier": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "Parents": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + "Children": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + }, + Required: []string{"Identifier", "Parents", "Children"}, + }, + }, } } diff --git a/pkg/registry/search/uniresource/children.go b/pkg/registry/search/relationship/children.go similarity index 87% rename from pkg/registry/search/uniresource/children.go rename to pkg/registry/search/relationship/children.go index c268ba7e..fb008745 100644 --- a/pkg/registry/search/uniresource/children.go +++ b/pkg/registry/search/relationship/children.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package uniresource +package relationship import ( "context" @@ -23,7 +23,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/klog/v2" - "github.com/KusionStack/karbour/pkg/registry/search/relationship" topologyutil "github.com/KusionStack/karbour/pkg/util/topology" "github.com/dominikbraun/graph" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -32,7 +31,7 @@ import ( ) // GetChildResourcesList returns an *unstructured.UnstructuredList representing all resources that matches the child GVK in the current namespace -func GetChildResourcesList(ctx context.Context, client *dynamic.DynamicClient, childRelation *relationship.Relationship, namespace string) (*unstructured.UnstructuredList, error) { +func GetChildResourcesList(ctx context.Context, client *dynamic.DynamicClient, childRelation *Relationship, namespace string) (*unstructured.UnstructuredList, error) { childAPIVersion := childRelation.Group + "/" + childRelation.Version childRes, err := topologyutil.GetGVRFromGVK(childAPIVersion, childRelation.Kind) if err != nil { @@ -56,7 +55,7 @@ func GetChildResourcesList(ctx context.Context, client *dynamic.DynamicClient, c } // GetChildren returns a graph that includes all of the child resources for the current obj that are described by the childRelation -func GetChildren(ctx context.Context, client *dynamic.DynamicClient, obj unstructured.Unstructured, childRelation *relationship.Relationship, namespace, objName string, objResourceNode relationship.ResourceGraphNode, relationshipGraph graph.Graph[string, relationship.RelationshipGraphNode], resourceGraph graph.Graph[string, relationship.ResourceGraphNode]) (graph.Graph[string, relationship.ResourceGraphNode], error) { +func GetChildren(ctx context.Context, client *dynamic.DynamicClient, obj unstructured.Unstructured, childRelation *Relationship, namespace, objName string, objResourceNode ResourceGraphNode, relationshipGraph graph.Graph[string, RelationshipGraphNode], resourceGraph graph.Graph[string, ResourceGraphNode]) (graph.Graph[string, ResourceGraphNode], error) { if childRelation.Type == "OwnerReference" { // If relationship type is ownerreference, honor that instead of relationship graph gv, _ := schema.ParseGroupVersion(childRelation.Group + "/" + childRelation.Version) @@ -115,11 +114,11 @@ func GetChildren(ctx context.Context, client *dynamic.DynamicClient, obj unstruc } // GetChildrenByOwnerReference returns a graph that includes all of the child resources for the current obj described by their children's OwnerReferences field -func GetChildrenByOwnerReference(childResList *unstructured.UnstructuredList, ctx context.Context, client *dynamic.DynamicClient, obj unstructured.Unstructured, childGVK schema.GroupVersionKind, relationshipGraph graph.Graph[string, relationship.RelationshipGraphNode], resourceGraph graph.Graph[string, relationship.ResourceGraphNode]) (graph.Graph[string, relationship.ResourceGraphNode], error) { +func GetChildrenByOwnerReference(childResList *unstructured.UnstructuredList, ctx context.Context, client *dynamic.DynamicClient, obj unstructured.Unstructured, childGVK schema.GroupVersionKind, relationshipGraph graph.Graph[string, RelationshipGraphNode], resourceGraph graph.Graph[string, ResourceGraphNode]) (graph.Graph[string, ResourceGraphNode], error) { // For ownerreference-identified children, look up all instances of the child GVK and filter by ownerreference klog.Infof("Using OwnerReferences to find children...\n") gv, _ := schema.ParseGroupVersion(obj.GetAPIVersion()) - objResourceNode := relationship.ResourceGraphNode{ + objResourceNode := ResourceGraphNode{ Group: gv.Group, Version: gv.Version, Kind: obj.GetKind(), @@ -133,7 +132,7 @@ func GetChildrenByOwnerReference(childResList *unstructured.UnstructuredList, ct klog.Infof("Child resource is: kind %s, name %s.\n", childRes.GetKind(), childRes.GetName()) klog.Infof("---------------------------------------------------------------------------\n") cgv, _ := schema.ParseGroupVersion(childRes.GetAPIVersion()) - childResourceNode := relationship.ResourceGraphNode{ + childResourceNode := ResourceGraphNode{ Group: cgv.Group, Version: cgv.Version, Kind: childRes.GetKind(), @@ -142,7 +141,7 @@ func GetChildrenByOwnerReference(childResList *unstructured.UnstructuredList, ct } resourceGraph.AddVertex(childResourceNode) resourceGraph.AddEdge(objResourceNode.GetHash(), childResourceNode.GetHash()) - childGVKOnGraph, _ := relationship.FindNodeOnGraph(relationshipGraph, childGVK.Group, childGVK.Version, childRes.GetKind()) + childGVKOnGraph, _ := FindNodeOnGraph(relationshipGraph, childGVK.Group, childGVK.Version, childRes.GetKind()) if len(childGVKOnGraph.Children) > 0 { // repeat for child resources // shorten call stack diff --git a/pkg/registry/search/uniresource/common.go b/pkg/registry/search/relationship/common.go similarity index 80% rename from pkg/registry/search/uniresource/common.go rename to pkg/registry/search/relationship/common.go index 8476effa..0b7b1d08 100644 --- a/pkg/registry/search/uniresource/common.go +++ b/pkg/registry/search/relationship/common.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package uniresource +package relationship import ( "context" @@ -26,11 +26,10 @@ import ( "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/client-go/dynamic" - "github.com/KusionStack/karbour/pkg/registry/search/relationship" topologyutil "github.com/KusionStack/karbour/pkg/util/topology" ) -func GetByJSONPath(relatedResList *unstructured.UnstructuredList, relationshipType string, ctx context.Context, client *dynamic.DynamicClient, obj unstructured.Unstructured, relation *relationship.Relationship, relatedGVK schema.GroupVersionKind, objResourceNode relationship.ResourceGraphNode, relationshipGraph graph.Graph[string, relationship.RelationshipGraphNode], resourceGraph graph.Graph[string, relationship.ResourceGraphNode]) (graph.Graph[string, relationship.ResourceGraphNode], error) { +func GetByJSONPath(relatedResList *unstructured.UnstructuredList, relationshipType string, ctx context.Context, client *dynamic.DynamicClient, obj unstructured.Unstructured, relation *Relationship, relatedGVK schema.GroupVersionKind, objResourceNode ResourceGraphNode, relationshipGraph graph.Graph[string, RelationshipGraphNode], resourceGraph graph.Graph[string, ResourceGraphNode]) (graph.Graph[string, ResourceGraphNode], error) { klog.Infof("Using direct references to find related resources...\n") var jpMatch bool var err error @@ -45,7 +44,7 @@ func GetByJSONPath(relatedResList *unstructured.UnstructuredList, relationshipTy klog.Infof("%s resource is: kind %s, name %s.\n", relationshipType, relatedRes.GetKind(), relatedRes.GetName()) klog.Infof("---------------------------------------------------------------------------\n") rgv, _ := schema.ParseGroupVersion(relatedRes.GetAPIVersion()) - relatedResourceNode := relationship.ResourceGraphNode{ + relatedResourceNode := ResourceGraphNode{ Group: rgv.Group, Version: rgv.Version, Kind: relatedRes.GetKind(), @@ -58,7 +57,7 @@ func GetByJSONPath(relatedResList *unstructured.UnstructuredList, relationshipTy } else { resourceGraph.AddEdge(objResourceNode.GetHash(), relatedResourceNode.GetHash()) } - relatedGVKOnGraph, _ := relationship.FindNodeOnGraph(relationshipGraph, relatedGVK.Group, relatedGVK.Version, relatedGVK.Kind) + relatedGVKOnGraph, _ := FindNodeOnGraph(relationshipGraph, relatedGVK.Group, relatedGVK.Version, relatedGVK.Kind) if relationshipType == "parent" && len(relatedGVKOnGraph.Parent) > 0 { // repeat for parent resources for _, parentRelation := range relatedGVKOnGraph.Parent { @@ -75,7 +74,7 @@ func GetByJSONPath(relatedResList *unstructured.UnstructuredList, relationshipTy return resourceGraph, nil } -func GetByLabelSelector(relatedResList *unstructured.UnstructuredList, relationshipType string, ctx context.Context, client *dynamic.DynamicClient, obj unstructured.Unstructured, relation *relationship.Relationship, relatedGVK schema.GroupVersionKind, objResourceNode relationship.ResourceGraphNode, relationshipGraph graph.Graph[string, relationship.RelationshipGraphNode], resourceGraph graph.Graph[string, relationship.ResourceGraphNode]) (graph.Graph[string, relationship.ResourceGraphNode], error) { +func GetByLabelSelector(relatedResList *unstructured.UnstructuredList, relationshipType string, ctx context.Context, client *dynamic.DynamicClient, obj unstructured.Unstructured, relation *Relationship, relatedGVK schema.GroupVersionKind, objResourceNode ResourceGraphNode, relationshipGraph graph.Graph[string, RelationshipGraphNode], resourceGraph graph.Graph[string, ResourceGraphNode]) (graph.Graph[string, ResourceGraphNode], error) { klog.Infof("Using label selectors to find related resources...\n") var labelsMatch bool var err error @@ -90,7 +89,7 @@ func GetByLabelSelector(relatedResList *unstructured.UnstructuredList, relations klog.Infof("%s resource is: kind %s, name %s.\n", relationshipType, relatedRes.GetKind(), relatedRes.GetName()) klog.Infof("---------------------------------------------------------------------------\n") rgv, _ := schema.ParseGroupVersion(relatedRes.GetAPIVersion()) - relatedResourceNode := relationship.ResourceGraphNode{ + relatedResourceNode := ResourceGraphNode{ Group: rgv.Group, Version: rgv.Version, Kind: relatedRes.GetKind(), @@ -103,7 +102,7 @@ func GetByLabelSelector(relatedResList *unstructured.UnstructuredList, relations } else { resourceGraph.AddEdge(objResourceNode.GetHash(), relatedResourceNode.GetHash()) } - relatedGVKOnGraph, _ := relationship.FindNodeOnGraph(relationshipGraph, relatedGVK.Group, relatedGVK.Version, relatedGVK.Kind) + relatedGVKOnGraph, _ := FindNodeOnGraph(relationshipGraph, relatedGVK.Group, relatedGVK.Version, relatedGVK.Kind) if relationshipType == "parent" && len(relatedGVKOnGraph.Parent) > 0 { for _, parentRelation := range relatedGVKOnGraph.Parent { resourceGraph, _ = GetParents(ctx, client, relatedRes, parentRelation, relatedRes.GetNamespace(), relatedRes.GetName(), relatedResourceNode, relationshipGraph, resourceGraph) diff --git a/pkg/registry/search/uniresource/parents.go b/pkg/registry/search/relationship/parents.go similarity index 87% rename from pkg/registry/search/uniresource/parents.go rename to pkg/registry/search/relationship/parents.go index a0268f06..a50c1a30 100644 --- a/pkg/registry/search/uniresource/parents.go +++ b/pkg/registry/search/relationship/parents.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package uniresource +package relationship import ( "context" @@ -23,7 +23,6 @@ import ( "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/klog/v2" - "github.com/KusionStack/karbour/pkg/registry/search/relationship" topologyutil "github.com/KusionStack/karbour/pkg/util/topology" "github.com/dominikbraun/graph" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -32,7 +31,7 @@ import ( ) // GetParentResourcesList returns an *unstructured.UnstructuredList representing all resources that matches the parent GVK in the current namespace -func GetParentResourcesList(ctx context.Context, client *dynamic.DynamicClient, parentRelation *relationship.Relationship, namespace string) (*unstructured.UnstructuredList, error) { +func GetParentResourcesList(ctx context.Context, client *dynamic.DynamicClient, parentRelation *Relationship, namespace string) (*unstructured.UnstructuredList, error) { parentAPIVersion := parentRelation.Group + "/" + parentRelation.Version parentRes, err := topologyutil.GetGVRFromGVK(parentAPIVersion, parentRelation.Kind) if err != nil { @@ -58,7 +57,7 @@ func GetParentResourcesList(ctx context.Context, client *dynamic.DynamicClient, } // GetParents returns a graph that includes all of the parent resources for the current obj that are described by the parentRelation -func GetParents(ctx context.Context, client *dynamic.DynamicClient, obj unstructured.Unstructured, parentRelation *relationship.Relationship, namespace, objName string, objResourceNode relationship.ResourceGraphNode, relationshipGraph graph.Graph[string, relationship.RelationshipGraphNode], resourceGraph graph.Graph[string, relationship.ResourceGraphNode]) (graph.Graph[string, relationship.ResourceGraphNode], error) { +func GetParents(ctx context.Context, client *dynamic.DynamicClient, obj unstructured.Unstructured, parentRelation *Relationship, namespace, objName string, objResourceNode ResourceGraphNode, relationshipGraph graph.Graph[string, RelationshipGraphNode], resourceGraph graph.Graph[string, ResourceGraphNode]) (graph.Graph[string, ResourceGraphNode], error) { var err error if parentRelation.Type == "OwnerReference" { // If relationship type is ownerreference, honor that instead of relationship graph @@ -96,7 +95,7 @@ func GetParents(ctx context.Context, client *dynamic.DynamicClient, obj unstruct } // GetParentsByOwnerReference returns a graph that includes all of the parent resources for the current obj described by its OwnerReferences field -func GetParentsByOwnerReference(ctx context.Context, client *dynamic.DynamicClient, obj unstructured.Unstructured, objResourceNode relationship.ResourceGraphNode, relationshipGraph graph.Graph[string, relationship.RelationshipGraphNode], resourceGraph graph.Graph[string, relationship.ResourceGraphNode]) (graph.Graph[string, relationship.ResourceGraphNode], error) { +func GetParentsByOwnerReference(ctx context.Context, client *dynamic.DynamicClient, obj unstructured.Unstructured, objResourceNode ResourceGraphNode, relationshipGraph graph.Graph[string, RelationshipGraphNode], resourceGraph graph.Graph[string, ResourceGraphNode]) (graph.Graph[string, ResourceGraphNode], error) { klog.Infof("Using OwnerReferences to find parents...\n") objName := obj.GetName() namespace := obj.GetNamespace() @@ -132,7 +131,7 @@ func GetParentsByOwnerReference(ctx context.Context, client *dynamic.DynamicClie klog.Infof("Parent resource is: kind %s, name %s.\n", parentRes.GetKind(), parentRes.GetName()) klog.Infof("---------------------------------------------------------------------------\n") pgv, _ := schema.ParseGroupVersion(parentRes.GetAPIVersion()) - parentResourceNode := relationship.ResourceGraphNode{ + parentResourceNode := ResourceGraphNode{ Group: pgv.Group, Version: pgv.Version, Kind: parentRes.GetKind(), diff --git a/pkg/registry/search/uniresource/topology.go b/pkg/registry/search/uniresource/topology.go index 08eaa001..ca079c03 100644 --- a/pkg/registry/search/uniresource/topology.go +++ b/pkg/registry/search/uniresource/topology.go @@ -46,11 +46,11 @@ type TopologyREST struct { // New returns an empty cluster proxy subresource. func (r *TopologyREST) New() runtime.Object { - return &search.UniresourceTopology{} + return &search.UniResourceTopology{} } func (r *TopologyREST) NewList() runtime.Object { - return &search.UniresourceTopologyList{} + return &search.UniResourceTopologyList{} } // Destroy cleans up resources on shutdown. @@ -65,7 +65,7 @@ func (r *TopologyREST) ConvertToTable(ctx context.Context, object runtime.Object } func (r *TopologyREST) List(ctx context.Context, options *internalversion.ListOptions) (runtime.Object, error) { - rt := &search.UniResourceList{} + rt := &search.UniResourceTopology{} resource, ok := filtersutil.ResourceDetailFrom(ctx) if !ok { return nil, fmt.Errorf("name, namespace, cluster, apiVersion and kind are used to locate a unique resource so they can't be empty") @@ -101,15 +101,14 @@ func (r *TopologyREST) List(ctx context.Context, options *internalversion.ListOp if err != nil { return rt, err } - rt.Items = append(rt.Items, unObj) } // Draw graph + // TODO: This is drawn on the server side, probably not needed eventually file, _ := os.Create("./resource.gv") _ = draw.DOT(g, file) - // am, _ := g.AdjacencyMap() - // spew.Dump(am) - + // Convert graph to a UniResourceTopology object and return + rt = r.ConvertToMap(g) return rt, nil } @@ -164,7 +163,7 @@ func (r *TopologyREST) GetResourceRelationship(ctx context.Context, obj unstruct // TODO: process error // Recursively find parents for _, objParent := range objGVKOnGraph.Parent { - resourceGraph, err = GetParents(ctx, client, obj, objParent, namespace, objName, objResourceNode, relationshipGraph, resourceGraph) + resourceGraph, err = relationship.GetParents(ctx, client, obj, objParent, namespace, objName, objResourceNode, relationshipGraph, resourceGraph) if err != nil { return nil, err } @@ -172,7 +171,7 @@ func (r *TopologyREST) GetResourceRelationship(ctx context.Context, obj unstruct // Recursively find children for _, objChild := range objGVKOnGraph.Children { - resourceGraph, err = GetChildren(ctx, client, obj, objChild, namespace, objName, objResourceNode, relationshipGraph, resourceGraph) + resourceGraph, err = relationship.GetChildren(ctx, client, obj, objChild, namespace, objName, objResourceNode, relationshipGraph, resourceGraph) if err != nil { return nil, err } @@ -180,3 +179,33 @@ func (r *TopologyREST) GetResourceRelationship(ctx context.Context, obj unstruct return resourceGraph, nil } + +func (r *TopologyREST) ConvertToMap(g graph.Graph[string, relationship.ResourceGraphNode]) *search.UniResourceTopology { + rt := &search.UniResourceTopology{} + + am, _ := g.AdjacencyMap() + rt.Graph = make(map[string]search.UniresourceNode) + for key, edgeMap := range am { + childList := make([]string, 0) + for edgeTarget := range edgeMap { + childList = append(childList, edgeTarget) + } + rt.Graph[key] = search.UniresourceNode{ + Identifier: key, + Children: childList, + } + } + + pm, _ := g.PredecessorMap() + for key, edgeMap := range pm { + parentList := make([]string, 0) + for edgeSource := range edgeMap { + parentList = append(parentList, edgeSource) + } + if node, ok := rt.Graph[key]; ok { + node.Parents = parentList + rt.Graph[key] = node + } + } + return rt +} diff --git a/pkg/registry/search/uniresource/yaml.go b/pkg/registry/search/uniresource/yaml.go index 6889d2b1..642582a7 100644 --- a/pkg/registry/search/uniresource/yaml.go +++ b/pkg/registry/search/uniresource/yaml.go @@ -71,11 +71,11 @@ func (r *YAMLREST) BuildDynamicClient(ctx context.Context) (*dynamic.DynamicClie // New returns an empty cluster proxy subresource. func (r *YAMLREST) New() runtime.Object { - return &search.UniresourceYAML{} + return &search.UniResourceYAML{} } func (r *YAMLREST) NewList() runtime.Object { - return &search.UniresourceYAMLList{} + return &search.UniResourceYAMLList{} } // Destroy cleans up resources on shutdown. @@ -90,10 +90,10 @@ func (r *YAMLREST) ConvertToTable(ctx context.Context, object runtime.Object, ta } func (r *YAMLREST) List(ctx context.Context, options *internalversion.ListOptions) (runtime.Object, error) { - rt := &search.UniResourceList{} + ry := &search.UniResourceYAML{} client, err := r.BuildDynamicClient(ctx) if err != nil { - return rt, err + return ry, err } resource, ok := filtersutil.ResourceDetailFrom(ctx) if !ok { @@ -119,6 +119,6 @@ func (r *YAMLREST) List(ctx context.Context, options *internalversion.ListOption panic(err.Error()) } klog.Infof("---\n%s\n", string(objYAML)) - rt.Items = append(rt.Items, res) - return rt, nil + ry.YAMLString = string(objYAML) + return ry, nil }