diff --git a/Makefile b/Makefile index f8acabb8..1128e7df 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,7 @@ SKIP_IMG_BUILD ?= false # Only enable a subset of reconcilers in porch controllers by default. Use the RECONCILERS # env variable to specify a specific list of reconcilers or use # RECONCILERS=* to enable all known reconcilers. -ALL_RECONCILERS="packagevariants,packagevariantsets,fleetsyncs" +ALL_RECONCILERS="packagevariants,packagevariantsets" ifndef RECONCILERS ENABLED_RECONCILERS="packagevariants,packagevariantsets" else diff --git a/controllers/config/crd/bases/config.porch.kpt.dev_fleetmembershipbindings.yaml b/controllers/config/crd/bases/config.porch.kpt.dev_fleetmembershipbindings.yaml deleted file mode 100644 index 7e200c47..00000000 --- a/controllers/config/crd/bases/config.porch.kpt.dev_fleetmembershipbindings.yaml +++ /dev/null @@ -1,88 +0,0 @@ -# Copyright 2024 The kpt and Nephio Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.14.0 - name: fleetmembershipbindings.config.porch.kpt.dev -spec: - group: config.porch.kpt.dev - names: - kind: FleetMembershipBinding - listKind: FleetMembershipBindingList - plural: fleetmembershipbindings - singular: fleetmembershipbinding - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - properties: - apiVersion: - description: |- - APIVersion defines the versioned schema of this representation of an object. - Servers should convert recognized schemas to the latest internal value, and - may reject unrecognized values. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources - type: string - data: - description: Data contains the discovered (synced) information - properties: - binding: - type: string - labels: - additionalProperties: - type: string - type: object - location: - type: string - membership: - type: string - name: - type: string - project: - type: string - scope: - type: string - scopeFullName: - type: string - scopeLocation: - type: string - scopeProject: - type: string - state: - properties: - code: - type: string - type: object - type: object - kind: - description: |- - Kind is a string value representing the REST resource this object represents. - Servers may infer this from the endpoint the client submits requests to. - Cannot be updated. - In CamelCase. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - metadata: - type: object - status: - type: object - type: object - served: true - storage: true - subresources: - status: {} diff --git a/controllers/config/crd/bases/config.porch.kpt.dev_fleetmemberships.yaml b/controllers/config/crd/bases/config.porch.kpt.dev_fleetmemberships.yaml deleted file mode 100644 index 36c04c7b..00000000 --- a/controllers/config/crd/bases/config.porch.kpt.dev_fleetmemberships.yaml +++ /dev/null @@ -1,80 +0,0 @@ -# Copyright 2024 The kpt and Nephio Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.14.0 - name: fleetmemberships.config.porch.kpt.dev -spec: - group: config.porch.kpt.dev - names: - kind: FleetMembership - listKind: FleetMembershipList - plural: fleetmemberships - singular: fleetmembership - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - properties: - apiVersion: - description: |- - APIVersion defines the versioned schema of this representation of an object. - Servers should convert recognized schemas to the latest internal value, and - may reject unrecognized values. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources - type: string - data: - description: Data contains the discovered (synced) information - properties: - description: - type: string - fullName: - type: string - labels: - additionalProperties: - type: string - type: object - location: - type: string - membership: - type: string - project: - type: string - state: - properties: - code: - type: string - type: object - type: object - kind: - description: |- - Kind is a string value representing the REST resource this object represents. - Servers may infer this from the endpoint the client submits requests to. - Cannot be updated. - In CamelCase. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - metadata: - type: object - status: - type: object - type: object - served: true - storage: true - subresources: - status: {} diff --git a/controllers/config/crd/bases/config.porch.kpt.dev_fleetscopes.yaml b/controllers/config/crd/bases/config.porch.kpt.dev_fleetscopes.yaml deleted file mode 100644 index fa2ad3da..00000000 --- a/controllers/config/crd/bases/config.porch.kpt.dev_fleetscopes.yaml +++ /dev/null @@ -1,78 +0,0 @@ -# Copyright 2024 The kpt and Nephio Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.14.0 - name: fleetscopes.config.porch.kpt.dev -spec: - group: config.porch.kpt.dev - names: - kind: FleetScope - listKind: FleetScopeList - plural: fleetscopes - singular: fleetscope - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - properties: - apiVersion: - description: |- - APIVersion defines the versioned schema of this representation of an object. - Servers should convert recognized schemas to the latest internal value, and - may reject unrecognized values. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources - type: string - data: - description: Data contains the discovered (synced) information - properties: - fullName: - type: string - labels: - additionalProperties: - type: string - type: object - location: - type: string - project: - type: string - scope: - type: string - state: - properties: - code: - type: string - type: object - type: object - kind: - description: |- - Kind is a string value representing the REST resource this object represents. - Servers may infer this from the endpoint the client submits requests to. - Cannot be updated. - In CamelCase. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - metadata: - type: object - status: - type: object - type: object - served: true - storage: true - subresources: - status: {} diff --git a/controllers/config/crd/bases/config.porch.kpt.dev_fleetsyncs.yaml b/controllers/config/crd/bases/config.porch.kpt.dev_fleetsyncs.yaml deleted file mode 100644 index 2f953e87..00000000 --- a/controllers/config/crd/bases/config.porch.kpt.dev_fleetsyncs.yaml +++ /dev/null @@ -1,138 +0,0 @@ -# Copyright 2024 The kpt and Nephio Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.14.0 - name: fleetsyncs.config.porch.kpt.dev -spec: - group: config.porch.kpt.dev - names: - kind: FleetSync - listKind: FleetSyncList - plural: fleetsyncs - singular: fleetsync - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - properties: - apiVersion: - description: |- - APIVersion defines the versioned schema of this representation of an object. - Servers should convert recognized schemas to the latest internal value, and - may reject unrecognized values. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources - type: string - kind: - description: |- - Kind is a string value representing the REST resource this object represents. - Servers may infer this from the endpoint the client submits requests to. - Cannot be updated. - In CamelCase. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - metadata: - type: object - spec: - properties: - projectIds: - items: - type: string - type: array - required: - - projectIds - type: object - status: - properties: - conditions: - items: - description: "Condition contains details for one aspect of the current - state of this API Resource.\n---\nThis struct is intended for - direct use as an array at the field path .status.conditions. For - example,\n\n\n\ttype FooStatus struct{\n\t // Represents the - observations of a foo's current state.\n\t // Known .status.conditions.type - are: \"Available\", \"Progressing\", and \"Degraded\"\n\t // - +patchMergeKey=type\n\t // +patchStrategy=merge\n\t // +listType=map\n\t - \ // +listMapKey=type\n\t Conditions []metav1.Condition `json:\"conditions,omitempty\" - patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`\n\n\n\t - \ // other fields\n\t}" - properties: - lastTransitionTime: - description: |- - lastTransitionTime is the last time the condition transitioned from one status to another. - This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable. - format: date-time - type: string - message: - description: |- - message is a human readable message indicating details about the transition. - This may be an empty string. - maxLength: 32768 - type: string - observedGeneration: - description: |- - observedGeneration represents the .metadata.generation that the condition was set based upon. - For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date - with respect to the current state of the instance. - format: int64 - minimum: 0 - type: integer - reason: - description: |- - reason contains a programmatic identifier indicating the reason for the condition's last transition. - Producers of specific condition types may define expected values and meanings for this field, - and whether the values are considered a guaranteed API. - The value should be a CamelCase string. - This field may not be empty. - maxLength: 1024 - minLength: 1 - pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$ - type: string - status: - description: status of the condition, one of True, False, Unknown. - enum: - - "True" - - "False" - - Unknown - type: string - type: - description: |- - type of condition in CamelCase or in foo.example.com/CamelCase. - --- - Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be - useful (see .node.status.conditions), the ability to deconflict is important. - The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt) - maxLength: 316 - pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$ - type: string - required: - - lastTransitionTime - - message - - reason - - status - - type - type: object - type: array - required: - - conditions - type: object - type: object - served: true - storage: true - subresources: - status: {} diff --git a/controllers/fleetsyncs/api/v1alpha1/fleetmembership_types.go b/controllers/fleetsyncs/api/v1alpha1/fleetmembership_types.go deleted file mode 100644 index 818b8c1c..00000000 --- a/controllers/fleetsyncs/api/v1alpha1/fleetmembership_types.go +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright 2023 The kpt and Nephio Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -type FleetMembershipData struct { - FullName string `json:"fullName,omitempty"` - Project string `json:"project,omitempty"` - Location string `json:"location,omitempty"` - Membership string `json:"membership,omitempty"` - Description string `json:"description,omitempty"` - - Labels map[string]string `json:"labels,omitempty"` - - State MembershipState `json:"state,omitempty"` -} - -type MembershipState struct { - Code MembershipStateCode `json:"code,omitempty"` -} - -type MembershipStateCode string - -const ( - MSCodeUnspecified MembershipStateCode = "unspecified" - MSCodeCreating MembershipStateCode = "creating" - MSCodeReady MembershipStateCode = "ready" - MSCodeDeleting MembershipStateCode = "deleting" - MSCodeUpdating MembershipStateCode = "updating" - MSCodeServiceUpdating MembershipStateCode = "serviceupdating" -) - -type FleetMembershipStatus struct { -} - -//+kubebuilder:object:root=true -//+kubebuilder:subresource:status - -type FleetMembership struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - // Data contains the discovered (synced) information - Data FleetMembershipData `json:"data,omitempty"` - Status FleetMembershipStatus `json:"status,omitempty"` -} - -//+kubebuilder:object:root=true - -type FleetMembershipList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []FleetMembership `json:"items"` -} - -func init() { - SchemeBuilder.Register(&FleetMembership{}, &FleetMembershipList{}) -} diff --git a/controllers/fleetsyncs/api/v1alpha1/fleetmembershipbindings_types.go b/controllers/fleetsyncs/api/v1alpha1/fleetmembershipbindings_types.go deleted file mode 100644 index 984c9089..00000000 --- a/controllers/fleetsyncs/api/v1alpha1/fleetmembershipbindings_types.go +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2023 The kpt and Nephio Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -type FleetMembershipBindingData struct { - FullName string `json:"name,omitempty"` - Project string `json:"project,omitempty"` - Location string `json:"location,omitempty"` - Membership string `json:"membership,omitempty"` - Binding string `json:"binding,omitempty"` - - ScopeFullName string `json:"scopeFullName,omitempty"` - ScopeProject string `json:"scopeProject,omitempty"` - ScopeLocation string `json:"scopeLocation,omitempty"` - Scope string `json:"scope,omitempty"` - - Labels map[string]string `json:"labels,omitempty"` - - State MembershipBindingState `json:"state,omitempty"` -} - -type MembershipBindingState struct { - Code MembershipBindingStateCode `json:"code,omitempty"` -} - -type MembershipBindingStateCode string - -const ( - MBSCodeUnspecified MembershipBindingStateCode = "unspecified" - MBSCodeCreating MembershipBindingStateCode = "creating" - MBSCodeReady MembershipBindingStateCode = "ready" - MBSCodeDeleting MembershipBindingStateCode = "deleting" - MBSCodeUpdating MembershipBindingStateCode = "updating" -) - -type FleetMembershipBindingStatus struct { -} - -//+kubebuilder:object:root=true -//+kubebuilder:subresource:status - -type FleetMembershipBinding struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - // Data contains the discovered (synced) information - Data FleetMembershipBindingData `json:"data,omitempty"` - Status FleetMembershipBindingStatus `json:"status,omitempty"` -} - -//+kubebuilder:object:root=true - -type FleetMembershipBindingList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []FleetMembershipBinding `json:"items"` -} - -func init() { - SchemeBuilder.Register(&FleetMembershipBinding{}, &FleetMembershipBindingList{}) -} diff --git a/controllers/fleetsyncs/api/v1alpha1/fleetscope_types.go b/controllers/fleetsyncs/api/v1alpha1/fleetscope_types.go deleted file mode 100644 index 734c9d18..00000000 --- a/controllers/fleetsyncs/api/v1alpha1/fleetscope_types.go +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2023 The kpt and Nephio Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -type FleetScopeData struct { - FullName string `json:"fullName,omitempty"` - Project string `json:"project,omitempty"` - Location string `json:"location,omitempty"` - Scope string `json:"scope,omitempty"` - - Labels map[string]string `json:"labels,omitempty"` - - State ScopeState `json:"state,omitempty"` -} - -type ScopeState struct { - Code ScopeStateCode `json:"code,omitempty"` -} - -type ScopeStateCode string - -const ( - SSCodeUnspecified ScopeStateCode = "unspecified" - SSCodeCreating ScopeStateCode = "creating" - SSCodeReady ScopeStateCode = "ready" - SSCodeDeleting ScopeStateCode = "deleting" - SSCodeUpdating ScopeStateCode = "updating" -) - -type FleetScopeStatus struct { -} - -//+kubebuilder:object:root=true -//+kubebuilder:subresource:status - -type FleetScope struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - // Data contains the discovered (synced) information - Data FleetScopeData `json:"data,omitempty"` - Status FleetScopeStatus `json:"status,omitempty"` -} - -//+kubebuilder:object:root=true - -type FleetScopeList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []FleetScope `json:"items"` -} - -func init() { - SchemeBuilder.Register(&FleetScope{}, &FleetScopeList{}) -} diff --git a/controllers/fleetsyncs/api/v1alpha1/fleetsync_types.go b/controllers/fleetsyncs/api/v1alpha1/fleetsync_types.go deleted file mode 100644 index 9ef3b030..00000000 --- a/controllers/fleetsyncs/api/v1alpha1/fleetsync_types.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2023 The kpt and Nephio Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -type FleetSyncSpec struct { - ProjectIds []string `json:"projectIds"` -} - -type FleetSyncStatus struct { - Conditions []metav1.Condition `json:"conditions"` -} - -//+kubebuilder:object:root=true -//+kubebuilder:subresource:status - -type FleetSync struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - Spec FleetSyncSpec `json:"spec,omitempty"` - Status FleetSyncStatus `json:"status,omitempty"` -} - -//+kubebuilder:object:root=true - -type FleetSyncList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` - Items []FleetSync `json:"items"` -} - -func init() { - SchemeBuilder.Register(&FleetSync{}, &FleetSyncList{}) -} diff --git a/controllers/fleetsyncs/api/v1alpha1/groupversion_info.go b/controllers/fleetsyncs/api/v1alpha1/groupversion_info.go deleted file mode 100644 index 6a5083fa..00000000 --- a/controllers/fleetsyncs/api/v1alpha1/groupversion_info.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2023 The kpt and Nephio Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package v1alpha1 contains API Schema definitions for the config.porch.kpt.dev v1alpha1 API group -// +kubebuilder:object:generate=true -// +groupName=config.porch.kpt.dev -package v1alpha1 - -import ( - "k8s.io/apimachinery/pkg/runtime/schema" - "sigs.k8s.io/controller-runtime/pkg/scheme" -) - -//go:generate go run sigs.k8s.io/controller-tools/cmd/controller-gen@v0.14.0 object:headerFile="../../../../scripts/boilerplate.go.txt" paths="./..." - -var ( - // GroupVersion is group version used to register these objects - GroupVersion = schema.GroupVersion{Group: "config.porch.kpt.dev", Version: "v1alpha1"} - - // SchemeBuilder is used to add go types to the GroupVersionKind scheme - SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} - - // AddToScheme adds the types in this group-version to the given scheme. - AddToScheme = SchemeBuilder.AddToScheme -) diff --git a/controllers/fleetsyncs/api/v1alpha1/zz_generated.deepcopy.go b/controllers/fleetsyncs/api/v1alpha1/zz_generated.deepcopy.go deleted file mode 100644 index 39fb0f3f..00000000 --- a/controllers/fleetsyncs/api/v1alpha1/zz_generated.deepcopy.go +++ /dev/null @@ -1,461 +0,0 @@ -//go:build !ignore_autogenerated - -// Copyright 2023-2024 The kpt and Nephio Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Code generated by controller-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FleetMembership) DeepCopyInto(out *FleetMembership) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Data.DeepCopyInto(&out.Data) - out.Status = in.Status -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FleetMembership. -func (in *FleetMembership) DeepCopy() *FleetMembership { - if in == nil { - return nil - } - out := new(FleetMembership) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *FleetMembership) 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 *FleetMembershipBinding) DeepCopyInto(out *FleetMembershipBinding) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Data.DeepCopyInto(&out.Data) - out.Status = in.Status -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FleetMembershipBinding. -func (in *FleetMembershipBinding) DeepCopy() *FleetMembershipBinding { - if in == nil { - return nil - } - out := new(FleetMembershipBinding) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *FleetMembershipBinding) 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 *FleetMembershipBindingData) DeepCopyInto(out *FleetMembershipBindingData) { - *out = *in - if in.Labels != nil { - in, out := &in.Labels, &out.Labels - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } - out.State = in.State -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FleetMembershipBindingData. -func (in *FleetMembershipBindingData) DeepCopy() *FleetMembershipBindingData { - if in == nil { - return nil - } - out := new(FleetMembershipBindingData) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FleetMembershipBindingList) DeepCopyInto(out *FleetMembershipBindingList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]FleetMembershipBinding, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FleetMembershipBindingList. -func (in *FleetMembershipBindingList) DeepCopy() *FleetMembershipBindingList { - if in == nil { - return nil - } - out := new(FleetMembershipBindingList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *FleetMembershipBindingList) 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 *FleetMembershipBindingStatus) DeepCopyInto(out *FleetMembershipBindingStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FleetMembershipBindingStatus. -func (in *FleetMembershipBindingStatus) DeepCopy() *FleetMembershipBindingStatus { - if in == nil { - return nil - } - out := new(FleetMembershipBindingStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FleetMembershipData) DeepCopyInto(out *FleetMembershipData) { - *out = *in - if in.Labels != nil { - in, out := &in.Labels, &out.Labels - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } - out.State = in.State -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FleetMembershipData. -func (in *FleetMembershipData) DeepCopy() *FleetMembershipData { - if in == nil { - return nil - } - out := new(FleetMembershipData) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FleetMembershipList) DeepCopyInto(out *FleetMembershipList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]FleetMembership, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FleetMembershipList. -func (in *FleetMembershipList) DeepCopy() *FleetMembershipList { - if in == nil { - return nil - } - out := new(FleetMembershipList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *FleetMembershipList) 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 *FleetMembershipStatus) DeepCopyInto(out *FleetMembershipStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FleetMembershipStatus. -func (in *FleetMembershipStatus) DeepCopy() *FleetMembershipStatus { - if in == nil { - return nil - } - out := new(FleetMembershipStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FleetScope) DeepCopyInto(out *FleetScope) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Data.DeepCopyInto(&out.Data) - out.Status = in.Status -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FleetScope. -func (in *FleetScope) DeepCopy() *FleetScope { - if in == nil { - return nil - } - out := new(FleetScope) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *FleetScope) 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 *FleetScopeData) DeepCopyInto(out *FleetScopeData) { - *out = *in - if in.Labels != nil { - in, out := &in.Labels, &out.Labels - *out = make(map[string]string, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } - out.State = in.State -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FleetScopeData. -func (in *FleetScopeData) DeepCopy() *FleetScopeData { - if in == nil { - return nil - } - out := new(FleetScopeData) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FleetScopeList) DeepCopyInto(out *FleetScopeList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]FleetScope, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FleetScopeList. -func (in *FleetScopeList) DeepCopy() *FleetScopeList { - if in == nil { - return nil - } - out := new(FleetScopeList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *FleetScopeList) 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 *FleetScopeStatus) DeepCopyInto(out *FleetScopeStatus) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FleetScopeStatus. -func (in *FleetScopeStatus) DeepCopy() *FleetScopeStatus { - if in == nil { - return nil - } - out := new(FleetScopeStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FleetSync) DeepCopyInto(out *FleetSync) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - in.Status.DeepCopyInto(&out.Status) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FleetSync. -func (in *FleetSync) DeepCopy() *FleetSync { - if in == nil { - return nil - } - out := new(FleetSync) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *FleetSync) 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 *FleetSyncList) DeepCopyInto(out *FleetSyncList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]FleetSync, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FleetSyncList. -func (in *FleetSyncList) DeepCopy() *FleetSyncList { - if in == nil { - return nil - } - out := new(FleetSyncList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *FleetSyncList) 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 *FleetSyncSpec) DeepCopyInto(out *FleetSyncSpec) { - *out = *in - if in.ProjectIds != nil { - in, out := &in.ProjectIds, &out.ProjectIds - *out = make([]string, len(*in)) - copy(*out, *in) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FleetSyncSpec. -func (in *FleetSyncSpec) DeepCopy() *FleetSyncSpec { - if in == nil { - return nil - } - out := new(FleetSyncSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *FleetSyncStatus) DeepCopyInto(out *FleetSyncStatus) { - *out = *in - if in.Conditions != nil { - in, out := &in.Conditions, &out.Conditions - *out = make([]v1.Condition, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FleetSyncStatus. -func (in *FleetSyncStatus) DeepCopy() *FleetSyncStatus { - if in == nil { - return nil - } - out := new(FleetSyncStatus) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MembershipBindingState) DeepCopyInto(out *MembershipBindingState) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MembershipBindingState. -func (in *MembershipBindingState) DeepCopy() *MembershipBindingState { - if in == nil { - return nil - } - out := new(MembershipBindingState) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MembershipState) DeepCopyInto(out *MembershipState) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MembershipState. -func (in *MembershipState) DeepCopy() *MembershipState { - if in == nil { - return nil - } - out := new(MembershipState) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ScopeState) DeepCopyInto(out *ScopeState) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ScopeState. -func (in *ScopeState) DeepCopy() *ScopeState { - if in == nil { - return nil - } - out := new(ScopeState) - in.DeepCopyInto(out) - return out -} diff --git a/controllers/fleetsyncs/config/rbac/role.yaml b/controllers/fleetsyncs/config/rbac/role.yaml deleted file mode 100644 index 95040013..00000000 --- a/controllers/fleetsyncs/config/rbac/role.yaml +++ /dev/null @@ -1,84 +0,0 @@ -# Copyright 2024 The kpt and Nephio Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: porch-controllers-fleetsyncs -rules: -- apiGroups: - - "" - resources: - - events - verbs: - - create - - patch -- apiGroups: - - config.porch.kpt.dev - resources: - - fleetmembershipbindings - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - config.porch.kpt.dev - resources: - - fleetmemberships - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - config.porch.kpt.dev - resources: - - fleetscopes - verbs: - - create - - delete - - get - - list - - patch - - update - - watch -- apiGroups: - - config.porch.kpt.dev - resources: - - fleetsyncs - verbs: - - get - - list - - watch -- apiGroups: - - config.porch.kpt.dev - resources: - - fleetsyncs/finalizers - verbs: - - update -- apiGroups: - - config.porch.kpt.dev - resources: - - fleetsyncs/status - verbs: - - get - - patch - - update diff --git a/controllers/fleetsyncs/config/rbac/rolebinding.yaml b/controllers/fleetsyncs/config/rbac/rolebinding.yaml deleted file mode 100644 index ad13d725..00000000 --- a/controllers/fleetsyncs/config/rbac/rolebinding.yaml +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright 2023 The kpt and Nephio Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: porch-system:porch-controllers-fleetsyncs -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: porch-controllers-fleetsyncs -subjects: -- kind: ServiceAccount - name: porch-controllers - namespace: porch-system \ No newline at end of file diff --git a/controllers/fleetsyncs/config/samples/simple.yaml b/controllers/fleetsyncs/config/samples/simple.yaml deleted file mode 100644 index c93cbb1f..00000000 --- a/controllers/fleetsyncs/config/samples/simple.yaml +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2023 The kpt and Nephio Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -apiVersion: config.porch.kpt.dev/v1alpha1 -kind: FleetSync -metadata: - name: simple - namespace: default -spec: - projectIds: - - example diff --git a/controllers/fleetsyncs/pkg/controllers/fleetsync/controller.go b/controllers/fleetsyncs/pkg/controllers/fleetsync/controller.go deleted file mode 100644 index 27f852cc..00000000 --- a/controllers/fleetsyncs/pkg/controllers/fleetsync/controller.go +++ /dev/null @@ -1,718 +0,0 @@ -// Copyright 2023 The kpt and Nephio Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package fleetsync - -import ( - "context" - "flag" - "fmt" - "strings" - - "k8s.io/client-go/tools/record" - - "github.com/nephio-project/porch/controllers/fleetsyncs/api/v1alpha1" - "github.com/nephio-project/porch/controllers/fleetsyncs/pkg/controllers/fleetsync/fleetpoller" - "github.com/nephio-project/porch/pkg/util" - gkehubv1 "google.golang.org/api/gkehub/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/api/meta" - - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/klog/v2" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - "sigs.k8s.io/controller-runtime/pkg/event" - "sigs.k8s.io/controller-runtime/pkg/handler" - "sigs.k8s.io/controller-runtime/pkg/source" -) - -const ( - fleetSyncLabel = "fleetsync.porch.kpt.dev/fleetsync" - projectLabel = "fleetsync.porch.kpt.dev/project" - scopeLabel = "fleetsync.porch.kpt.dev/scope" - membershipLabel = "fleetsync.porch.kpt.dev/membership" - nameMaxLen = 63 - nameHashLen = 8 -) - -type Options struct { -} - -func (o *Options) InitDefaults() { -} - -func (o *Options) BindFlags(prefix string, flags *flag.FlagSet) { -} - -func NewFleetSyncReconciler() *FleetSyncReconciler { - return &FleetSyncReconciler{} -} - -type FleetSyncReconciler struct { - Options - - client.Client - - poller *fleetpoller.Poller - recorder record.EventRecorder -} - -//go:generate go run sigs.k8s.io/controller-tools/cmd/controller-gen@v0.14.0 rbac:headerFile=../../../../../scripts/boilerplate.yaml.txt,roleName=porch-controllers-fleetsyncs webhook paths="." output:rbac:artifacts:config=../../../config/rbac - -//+kubebuilder:rbac:groups=config.porch.kpt.dev,resources=fleetsyncs,verbs=get;list;watch -//+kubebuilder:rbac:groups=config.porch.kpt.dev,resources=fleetsyncs/status,verbs=get;update;patch -//+kubebuilder:rbac:groups=config.porch.kpt.dev,resources=fleetsyncs/finalizers,verbs=update -//+kubebuilder:rbac:groups=config.porch.kpt.dev,resources=fleetmemberships,verbs=get;list;watch;create;update;patch;delete -//+kubebuilder:rbac:groups=config.porch.kpt.dev,resources=fleetmembershipbindings,verbs=get;list;watch;create;update;patch;delete -//+kubebuilder:rbac:groups=config.porch.kpt.dev,resources=fleetscopes,verbs=get;list;watch;create;update;patch;delete -//+kubebuilder:rbac:groups="",resources=events,verbs=create;patch - -func (r *FleetSyncReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { - var fleetsync v1alpha1.FleetSync - if err := r.Get(ctx, req.NamespacedName, &fleetsync); err != nil { - return ctrl.Result{}, client.IgnoreNotFound(err) - } - orig := fleetsync.DeepCopy() - - myFinalizerName := "config.porch.kpt.dev/fleetsyncs" - if fleetsync.ObjectMeta.DeletionTimestamp.IsZero() { - // The object is not being deleted, so if it does not have our finalizer, - // then lets add the finalizer and update the object. This is equivalent - // registering our finalizer. - if !controllerutil.ContainsFinalizer(&fleetsync, myFinalizerName) { - controllerutil.AddFinalizer(&fleetsync, myFinalizerName) - if err := r.Update(ctx, &fleetsync); err != nil { - return ctrl.Result{}, fmt.Errorf("error adding finalizer: %w", err) - } - } - } else { - // The object is being deleted - if controllerutil.ContainsFinalizer(&fleetsync, myFinalizerName) { - // remove our finalizer from the list and update it. - r.poller.StopPollingForFleetSync(req.NamespacedName) - controllerutil.RemoveFinalizer(&fleetsync, myFinalizerName) - if err := r.Update(ctx, &fleetsync); err != nil { - return ctrl.Result{}, fmt.Errorf("failed to update %s after delete finalizer: %w", req.Name, err) - } - } - // Stop reconciliation as the item is being deleted - return ctrl.Result{}, nil - } - klog.Infof("Reconciling %s", req.NamespacedName.String()) - - r.poller.VerifyProjectIdsForFleetSync(req.NamespacedName, fleetsync.Spec.ProjectIds) - - allFailed := true - for _, projectId := range fleetsync.Spec.ProjectIds { - err := r.reconcileProject(ctx, projectId, orig, &fleetsync) - if err != nil { - r.recorder.Event(&fleetsync, corev1.EventTypeWarning, "ProjectSyncError", - fmt.Sprintf("could not sync project %q: %s", projectId, err.Error())) - } else { - allFailed = false - } - } - if allFailed { - r.setErrorCondition(ctx, orig, &fleetsync, "No projects succesfully reconciled") - } - - return ctrl.Result{}, nil -} - -func (r *FleetSyncReconciler) reconcileProject(ctx context.Context, projectId string, orig, fleetsync *v1alpha1.FleetSync) error { - pr, found := r.poller.LatestResult(projectId) - if !found { - r.recorder.Event(fleetsync, corev1.EventTypeNormal, "ProjectSyncPending", - fmt.Sprintf("Waiting for sync for project %q", projectId)) - return nil - } - - // If there are any errors for this project ID, we will not - // sync any data for the project. - if pr.HasError() { - return pr.ErrorSummary() - } - - err := r.reconcileMemberships(ctx, projectId, pr, fleetsync) - if err != nil { - return err - } - - err = r.reconcileScopes(ctx, projectId, pr, fleetsync) - if err != nil { - return err - } - - err = r.reconcileMembershipBindings(ctx, projectId, pr, fleetsync) - if err != nil { - return err - } - - r.setReadyCondition(ctx, orig, fleetsync) - return nil -} - -func (r *FleetSyncReconciler) reconcileMemberships(ctx context.Context, projectId string, pr *fleetpoller.PollResult, fleetsync *v1alpha1.FleetSync) error { - existingMemberships, err := r.findExistingMemberships(ctx, fleetsync.Name, fleetsync.Namespace, projectId) - if err != nil { - return err - } - - for _, hubm := range pr.Memberships { - name, err := membershipId(hubm) - if err != nil { - klog.Warningf("could not create new membership: %s", err.Error()) - continue - } - - existing, found := existingMemberships[name] - if !found { - m, err := newMembership(hubm, fleetsync) - if err != nil { - klog.Warningf("could not create new membership: %s", err.Error()) - continue - } - // TODO: We should probably use SSA here rather than Create/Update. - if err := r.Create(ctx, m); err != nil { - return err - } - continue - } - - updated := existing.DeepCopy() - err = updateMembership(hubm, fleetsync, updated) - if err != nil { - klog.Warningf("could not update membership: %s", err.Error()) - continue - } - - if !equality.Semantic.DeepEqual(updated.Data, existing.Data) { - if err := r.Update(ctx, updated); err != nil { - return err - } - } - } - - for name, m := range existingMemberships { - found := false - for _, hubm := range pr.Memberships { - hubmName, err := membershipId(hubm) - if err != nil { - klog.Warning(err) - continue - } - if hubmName == name { - found = true - } - } - if !found { - if err := r.Delete(ctx, m); err != nil { - return err - } - } - } - - return nil -} - -func (r *FleetSyncReconciler) reconcileScopes(ctx context.Context, projectId string, pr *fleetpoller.PollResult, fleetsync *v1alpha1.FleetSync) error { - existingScopes, err := r.findExistingScopes(ctx, fleetsync.Name, fleetsync.Namespace, projectId) - if err != nil { - return err - } - - for _, res := range pr.Scopes { - name, err := scopeId(res) - if err != nil { - klog.Warningf("could not create new scope: %s", err.Error()) - continue - } - - existing, found := existingScopes[name] - if !found { - m, err := newScope(res, fleetsync) - if err != nil { - klog.Warningf("could not create new scope: %s", err.Error()) - continue - } - // TODO: We should probably use SSA here rather than Create/Update. - if err := r.Create(ctx, m); err != nil { - return err - } - continue - } - - updated := existing.DeepCopy() - err = updateScope(res, fleetsync, updated) - if err != nil { - klog.Warningf("could not update scope: %s", err.Error()) - continue - } - - if !equality.Semantic.DeepEqual(updated.Data, existing.Data) { - if err := r.Update(ctx, updated); err != nil { - return err - } - } - } - - for name, m := range existingScopes { - found := false - for _, res := range pr.Scopes { - resName, err := scopeId(res) - if err != nil { - klog.Warning(err) - continue - } - if resName == name { - found = true - } - } - if !found { - if err := r.Delete(ctx, m); err != nil { - return err - } - } - } - - return nil -} - -func (r *FleetSyncReconciler) reconcileMembershipBindings(ctx context.Context, projectId string, pr *fleetpoller.PollResult, fleetsync *v1alpha1.FleetSync) error { - existingBindings, err := r.findExistingMembershipBindings(ctx, fleetsync.Name, fleetsync.Namespace, projectId) - if err != nil { - return err - } - - for _, res := range pr.Bindings { - name, err := bindingId(res) - if err != nil { - klog.Warningf("could not create new binding: %s", err.Error()) - continue - } - - existing, found := existingBindings[name] - if !found { - m, err := newMembershipBinding(res, fleetsync) - if err != nil { - klog.Warningf("could not create new binding: %s", err.Error()) - continue - } - // TODO: We should probably use SSA here rather than Create/Update. - if err := r.Create(ctx, m); err != nil { - return err - } - continue - } - - updated := existing.DeepCopy() - err = updateMembershipBinding(res, fleetsync, updated) - if err != nil { - klog.Warningf("could not update binding: %s", err.Error()) - continue - } - - if !equality.Semantic.DeepEqual(updated.Data, existing.Data) { - if err := r.Update(ctx, updated); err != nil { - return err - } - } - } - - for name, m := range existingBindings { - found := false - for _, res := range pr.Bindings { - resName, err := bindingId(res) - if err != nil { - klog.Warning(err) - continue - } - if resName == name { - found = true - } - } - if !found { - if err := r.Delete(ctx, m); err != nil { - return err - } - } - } - - return nil -} - -func (r *FleetSyncReconciler) setReadyCondition(ctx context.Context, orig, fleetsync *v1alpha1.FleetSync) { - meta.SetStatusCondition(&fleetsync.Status.Conditions, metav1.Condition{ - Type: "Ready", - Status: metav1.ConditionTrue, - ObservedGeneration: fleetsync.Generation, - Reason: "Synced", - }) - meta.SetStatusCondition(&fleetsync.Status.Conditions, metav1.Condition{ - Type: "Stalled", - Status: metav1.ConditionFalse, - ObservedGeneration: fleetsync.Generation, - Reason: "Synced", - }) - if err := r.updateStatus(ctx, orig, fleetsync); err != nil { - klog.Errorf("Error updating status for %s/%s: %v", fleetsync.Namespace, fleetsync.Name, err) - } -} - -func (r *FleetSyncReconciler) setErrorCondition(ctx context.Context, orig, fleetsync *v1alpha1.FleetSync, message string) { - meta.SetStatusCondition(&fleetsync.Status.Conditions, metav1.Condition{ - Type: "Ready", - Status: metav1.ConditionFalse, - ObservedGeneration: fleetsync.Generation, - Reason: "FleetSyncError", - }) - meta.SetStatusCondition(&fleetsync.Status.Conditions, metav1.Condition{ - Type: "Stalled", - Status: metav1.ConditionTrue, - ObservedGeneration: fleetsync.Generation, - Reason: "FleetSyncError", - Message: message, - }) - if err := r.updateStatus(ctx, orig, fleetsync); err != nil { - klog.Errorf("Error updating status for %s/%s: %v", fleetsync.Namespace, fleetsync.Name, err) - } -} - -func newMembership(hubMembership *gkehubv1.Membership, fleetsync *v1alpha1.FleetSync) (*v1alpha1.FleetMembership, error) { - id, err := membershipId(hubMembership) - if err != nil { - return nil, err - } - - t := true - fm := &v1alpha1.FleetMembership{ - ObjectMeta: metav1.ObjectMeta{ - Name: id, - Namespace: fleetsync.Namespace, - Labels: map[string]string{}, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: fleetsync.APIVersion, - Kind: fleetsync.Kind, - Name: fleetsync.Name, - UID: fleetsync.UID, - Controller: &t, - }, - }, - }, - } - - return fm, updateMembership(hubMembership, fleetsync, fm) -} - -func updateMembership(hubMembership *gkehubv1.Membership, fleetsync *v1alpha1.FleetSync, fm *v1alpha1.FleetMembership) error { - segments := strings.Split(hubMembership.Name, "/") - if len(segments) != 6 { - return fmt.Errorf("invalid membership name %q; should be 6 segments", hubMembership.Name) - } - - fm.ObjectMeta.Labels[fleetSyncLabel] = fleetsync.Name - fm.ObjectMeta.Labels[projectLabel] = segments[1] - fm.ObjectMeta.Labels[membershipLabel] = segments[5] - - fm.Data = v1alpha1.FleetMembershipData{ - FullName: hubMembership.Name, - Project: segments[1], - Location: segments[3], - Membership: segments[5], - Description: hubMembership.Description, - Labels: hubMembership.Labels, - State: v1alpha1.MembershipState{ - Code: toMembershipStateCode(hubMembership.State), - }, - } - - return nil -} - -func toMembershipStateCode(ms *gkehubv1.MembershipState) v1alpha1.MembershipStateCode { - if ms == nil { - return v1alpha1.MSCodeUnspecified - } - - switch ms.Code { - case "CODE_UNSPECIFIED": - return v1alpha1.MSCodeUnspecified - case "CREATING": - return v1alpha1.MSCodeCreating - case "READY": - return v1alpha1.MSCodeReady - case "DELETING": - return v1alpha1.MSCodeDeleting - case "UPDATING": - return v1alpha1.MSCodeUpdating - case "SERVICE_UPDATING": - return v1alpha1.MSCodeServiceUpdating - default: - return v1alpha1.MSCodeUnspecified - } -} - -func membershipId(hubMembership *gkehubv1.Membership) (string, error) { - // projects/*/locations/*/memberships/{membership_id} - segments := strings.Split(hubMembership.Name, "/") - if len(segments) != 6 { - return "", fmt.Errorf("invalid membership name %q; should be 6 segments", hubMembership.Name) - } - return util.KubernetesName(segments[1]+"-"+segments[3]+"-"+segments[5], nameHashLen, nameMaxLen), nil -} - -func newScope(hubScope *gkehubv1.Scope, fleetsync *v1alpha1.FleetSync) (*v1alpha1.FleetScope, error) { - id, err := scopeId(hubScope) - if err != nil { - return nil, err - } - - t := true - f := &v1alpha1.FleetScope{ - ObjectMeta: metav1.ObjectMeta{ - Name: id, - Namespace: fleetsync.Namespace, - Labels: map[string]string{}, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: fleetsync.APIVersion, - Kind: fleetsync.Kind, - Name: fleetsync.Name, - UID: fleetsync.UID, - Controller: &t, - }, - }, - }, - } - - return f, updateScope(hubScope, fleetsync, f) -} - -func updateScope(hubScope *gkehubv1.Scope, fleetsync *v1alpha1.FleetSync, f *v1alpha1.FleetScope) error { - segments := strings.Split(hubScope.Name, "/") - if len(segments) != 6 { - return fmt.Errorf("invalid scope name %q; should be 6 segments", hubScope.Name) - } - - f.ObjectMeta.Labels[fleetSyncLabel] = fleetsync.Name - f.ObjectMeta.Labels[projectLabel] = segments[1] - f.ObjectMeta.Labels[scopeLabel] = segments[5] - - f.Data = v1alpha1.FleetScopeData{ - FullName: hubScope.Name, - Project: segments[1], - Location: segments[3], - Scope: segments[5], - Labels: hubScope.Labels, - State: v1alpha1.ScopeState{ - Code: toScopeStateCode(hubScope.State), - }, - } - - return nil -} - -func toScopeStateCode(ms *gkehubv1.ScopeLifecycleState) v1alpha1.ScopeStateCode { - if ms == nil { - return v1alpha1.SSCodeUnspecified - } - - switch ms.Code { - case "CODE_UNSPECIFIED": - return v1alpha1.SSCodeUnspecified - case "CREATING": - return v1alpha1.SSCodeCreating - case "READY": - return v1alpha1.SSCodeReady - case "DELETING": - return v1alpha1.SSCodeDeleting - case "UPDATING": - return v1alpha1.SSCodeUpdating - default: - return v1alpha1.SSCodeUnspecified - } -} - -func scopeId(scope *gkehubv1.Scope) (string, error) { - // `projects/{project}/locations/{location}/scopes/{scope}` - segments := strings.Split(scope.Name, "/") - if len(segments) != 6 { - return "", fmt.Errorf("invalid scope name %q; should be 6 segments", scope.Name) - } - return util.KubernetesName(segments[1]+"-"+segments[3]+"-"+segments[5], nameHashLen, nameMaxLen), nil -} - -func newMembershipBinding(hubBinding *gkehubv1.MembershipBinding, fleetsync *v1alpha1.FleetSync) (*v1alpha1.FleetMembershipBinding, error) { - id, err := bindingId(hubBinding) - if err != nil { - return nil, err - } - - t := true - f := &v1alpha1.FleetMembershipBinding{ - ObjectMeta: metav1.ObjectMeta{ - Name: id, - Namespace: fleetsync.Namespace, - Labels: map[string]string{}, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: fleetsync.APIVersion, - Kind: fleetsync.Kind, - Name: fleetsync.Name, - UID: fleetsync.UID, - Controller: &t, - }, - }, - }, - } - - return f, updateMembershipBinding(hubBinding, fleetsync, f) -} - -func updateMembershipBinding(hubBinding *gkehubv1.MembershipBinding, fleetsync *v1alpha1.FleetSync, f *v1alpha1.FleetMembershipBinding) error { - segments := strings.Split(hubBinding.Name, "/") - if len(segments) != 8 { - return fmt.Errorf("invalid binding name %q; should be 8 segments", hubBinding.Name) - } - - scopeSegs := strings.Split(hubBinding.Scope, "/") - if len(scopeSegs) != 6 { - return fmt.Errorf("invalid scope name %q; should be 6 segments", hubBinding.Scope) - } - - f.ObjectMeta.Labels[fleetSyncLabel] = fleetsync.Name - f.ObjectMeta.Labels[projectLabel] = segments[1] - f.ObjectMeta.Labels[membershipLabel] = segments[5] - f.ObjectMeta.Labels[scopeLabel] = scopeSegs[5] - - f.Data = v1alpha1.FleetMembershipBindingData{ - FullName: hubBinding.Name, - Project: segments[1], - Location: segments[3], - Membership: segments[5], - Binding: segments[7], - Scope: hubBinding.Scope, - Labels: hubBinding.Labels, - State: v1alpha1.MembershipBindingState{ - Code: toMembershipBindingStateCode(hubBinding.State), - }, - } - - return nil -} - -func toMembershipBindingStateCode(ms *gkehubv1.MembershipBindingLifecycleState) v1alpha1.MembershipBindingStateCode { - if ms == nil { - return v1alpha1.MBSCodeUnspecified - } - - switch ms.Code { - case "CODE_UNSPECIFIED": - return v1alpha1.MBSCodeUnspecified - case "CREATING": - return v1alpha1.MBSCodeCreating - case "READY": - return v1alpha1.MBSCodeReady - case "DELETING": - return v1alpha1.MBSCodeDeleting - case "UPDATING": - return v1alpha1.MBSCodeUpdating - default: - return v1alpha1.MBSCodeUnspecified - } -} - -func bindingId(binding *gkehubv1.MembershipBinding) (string, error) { - // `projects/{project}/locations/{location}/memberships/{membership}/bindings/{membershipbinding}` - segments := strings.Split(binding.Name, "/") - if len(segments) != 8 { - return "", fmt.Errorf("invalid membership binding name %q; should be 8 segments", binding.Name) - } - return util.KubernetesName(segments[1]+"-"+segments[3]+"-"+segments[5]+"-"+segments[7], nameHashLen, nameMaxLen), nil -} - -func (r *FleetSyncReconciler) updateStatus(ctx context.Context, orig, new *v1alpha1.FleetSync) error { - if equality.Semantic.DeepEqual(orig.Status, new.Status) { - return nil - } - return r.Status().Update(ctx, new) -} - -func (r *FleetSyncReconciler) findExistingMemberships(ctx context.Context, fsName, fsNamespace, projectId string) (map[string]*v1alpha1.FleetMembership, error) { - var list v1alpha1.FleetMembershipList - if err := r.List(ctx, &list, client.MatchingLabels{fleetSyncLabel: fsName, projectLabel: projectId}, client.InNamespace(fsNamespace)); err != nil { - return nil, err - } - - items := make(map[string]*v1alpha1.FleetMembership, len(list.Items)) - for i := range list.Items { - item := &list.Items[i] - items[item.Name] = item - } - return items, nil -} - -func (r *FleetSyncReconciler) findExistingScopes(ctx context.Context, fsName, fsNamespace, projectId string) (map[string]*v1alpha1.FleetScope, error) { - var list v1alpha1.FleetScopeList - if err := r.List(ctx, &list, client.MatchingLabels{fleetSyncLabel: fsName, projectLabel: projectId}, client.InNamespace(fsNamespace)); err != nil { - return nil, err - } - - items := make(map[string]*v1alpha1.FleetScope, len(list.Items)) - for i := range list.Items { - item := &list.Items[i] - items[item.Name] = item - } - return items, nil -} - -func (r *FleetSyncReconciler) findExistingMembershipBindings(ctx context.Context, fsName, fsNamespace, projectId string) (map[string]*v1alpha1.FleetMembershipBinding, error) { - var list v1alpha1.FleetMembershipBindingList - if err := r.List(ctx, &list, client.MatchingLabels{fleetSyncLabel: fsName, projectLabel: projectId}, client.InNamespace(fsNamespace)); err != nil { - return nil, err - } - - items := make(map[string]*v1alpha1.FleetMembershipBinding, len(list.Items)) - for i := range list.Items { - item := &list.Items[i] - items[item.Name] = item - } - return items, nil -} - -// SetupWithManager sets up the controller with the Manager. -func (r *FleetSyncReconciler) SetupWithManager(mgr ctrl.Manager) error { - if err := v1alpha1.AddToScheme(mgr.GetScheme()); err != nil { - return err - } - - r.Client = mgr.GetClient() - r.recorder = mgr.GetEventRecorderFor("fleetsync-controller") - - channel := make(chan event.GenericEvent) - r.poller = fleetpoller.NewPoller(channel) - r.poller.Start() - - return ctrl.NewControllerManagedBy(mgr). - For(&v1alpha1.FleetSync{}). - Owns(&v1alpha1.FleetMembership{}). - Owns(&v1alpha1.FleetScope{}). - Owns(&v1alpha1.FleetMembershipBinding{}). - WatchesRawSource(&source.Channel{Source: channel}, &handler.EnqueueRequestForObject{}). - Complete(r) -} diff --git a/controllers/fleetsyncs/pkg/controllers/fleetsync/fleetpoller/poller.go b/controllers/fleetsyncs/pkg/controllers/fleetsync/fleetpoller/poller.go deleted file mode 100644 index 9c74567b..00000000 --- a/controllers/fleetsyncs/pkg/controllers/fleetsync/fleetpoller/poller.go +++ /dev/null @@ -1,307 +0,0 @@ -// Copyright 2023 The kpt and Nephio Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package fleetpoller - -import ( - "context" - "fmt" - "strings" - "sync" - "time" - - "github.com/nephio-project/porch/controllers/fleetsyncs/api/v1alpha1" - gkehubv1 "google.golang.org/api/gkehub/v1" - "k8s.io/apimachinery/pkg/api/equality" - "k8s.io/apimachinery/pkg/types" - "k8s.io/klog/v2" - "sigs.k8s.io/controller-runtime/pkg/event" -) - -func NewPoller(channel chan event.GenericEvent) *Poller { - return &Poller{ - channel: channel, - projectIds: make(map[string][]types.NamespacedName), - } -} - -type Poller struct { - channel chan event.GenericEvent - cancelFunc context.CancelFunc - - projectIds map[string][]types.NamespacedName - pollResult map[string]*PollResult - mutex sync.Mutex -} - -func (p *Poller) Start() { - ctx, cancelFunc := context.WithCancel(context.Background()) - p.cancelFunc = cancelFunc - go func() { - ticker := time.NewTicker(30 * time.Second) - for { - select { - case <-ticker.C: - p.pollOnce(ctx) - case <-ctx.Done(): - return - } - } - }() -} - -func (p *Poller) VerifyProjectIdsForFleetSync(fleetSync types.NamespacedName, projectIds []string) { - p.mutex.Lock() - defer p.mutex.Unlock() - // This is not a very efficient way to do this... - for projectId, nns := range p.projectIds { - var newNns []types.NamespacedName - for _, nn := range nns { - if nn != fleetSync { - newNns = append(newNns, nn) - } - } - p.projectIds[projectId] = newNns - } - - for _, projectId := range projectIds { - if nns, found := p.projectIds[projectId]; !found { - p.projectIds[projectId] = []types.NamespacedName{fleetSync} - } else { - p.projectIds[projectId] = append(nns, fleetSync) - } - } - - klog.Infof("projectIds count %d", len(p.projectIds)) - for projectId := range p.projectIds { - klog.Infof("ProjectId: %s", projectId) - } -} - -func (p *Poller) StopPollingForFleetSync(fleetSync types.NamespacedName) { - p.mutex.Lock() - defer p.mutex.Unlock() - // This is not a very efficient way to do this... - for projectId, nns := range p.projectIds { - var newNns []types.NamespacedName - for _, nn := range nns { - if nn != fleetSync { - newNns = append(newNns, nn) - } - } - p.projectIds[projectId] = newNns - } -} - -func (p *Poller) LatestResult(projectId string) (*PollResult, bool) { - p.mutex.Lock() - defer p.mutex.Unlock() - res, found := p.pollResult[projectId] - if !found { - return nil, false - } - return res, true -} - -type PollResult struct { - MembershipsErr error - Memberships []*gkehubv1.Membership - - ScopesErr error - Scopes []*gkehubv1.Scope - - BindingsErrs []error - Bindings []*gkehubv1.MembershipBinding -} - -func (pr *PollResult) HasError() bool { - return pr.MembershipsErr != nil || pr.ScopesErr != nil || len(pr.BindingsErrs) > 0 -} - -func (pr *PollResult) ErrorSummary() error { - if !pr.HasError() { - return nil - } - - var builder strings.Builder - builder.WriteString("Errors:") - if pr.MembershipsErr != nil { - builder.WriteString(fmt.Sprintf(" [memberships: %s]", pr.MembershipsErr.Error())) - } - if pr.ScopesErr != nil { - builder.WriteString(fmt.Sprintf(" [scopes: %s]", pr.ScopesErr.Error())) - } - if len(pr.BindingsErrs) > 0 { - builder.WriteString(fmt.Sprintf(" [bindings: %d errors", len(pr.BindingsErrs))) - for _, err := range pr.BindingsErrs { - builder.WriteString(fmt.Sprintf(", %s", err.Error())) - } - } - return fmt.Errorf(builder.String()) -} - -func (p *Poller) pollOnce(ctx context.Context) { - var projectIds map[string][]types.NamespacedName - var previousPollResult map[string]*PollResult - func() { - p.mutex.Lock() - defer p.mutex.Unlock() - projectIds = p.projectIds - previousPollResult = p.pollResult - }() - - klog.Infof("Polling %d projects", len(projectIds)) - - newPollResult := p.poll(ctx, projectIds) - - toNotify := make(map[types.NamespacedName]struct{}) - for projectId, newRes := range newPollResult { - klog.Infof("Checking for changes for projectId %s", projectId) - oldRes, found := previousPollResult[projectId] - // No result from a previous run means it must have been - // added later. Schedule a reconcile for all FleetSyncs - // referencing the projectId. - if !found { - klog.Infof("Not found") - nns := projectIds[projectId] - for _, nn := range nns { - toNotify[nn] = struct{}{} - } - continue - } - // If either the previous poll or the current poll errored - // out, trigger a reconcile. - if newRes.HasError() || oldRes.HasError() { - klog.Infof("Has errors") - nns := projectIds[projectId] - for _, nn := range nns { - toNotify[nn] = struct{}{} - } - continue - } - - // If any of the memberships have changed, trigger a reconcile. - if !equality.Semantic.DeepEqual(newRes, oldRes) { - klog.Infof("Not equal") - nns := projectIds[projectId] - for _, nn := range nns { - toNotify[nn] = struct{}{} - } - } - } - - func() { - p.mutex.Lock() - defer p.mutex.Unlock() - p.pollResult = newPollResult - }() - - // Notify after we have updated the poll result, so any triggered - // reconcile will see the latest data. - for nn := range toNotify { - klog.Infof("Triggering reconcile for %s", nn.String()) - fs := &v1alpha1.FleetSync{} - fs.SetName(nn.Name) - fs.SetNamespace(nn.Namespace) - p.channel <- event.GenericEvent{ - Object: fs, - } - } -} - -func (p *Poller) poll(ctx context.Context, projectIds map[string][]types.NamespacedName) map[string]*PollResult { - res := make(map[string]*PollResult) - for projectId := range projectIds { - pr := &PollResult{} - res[projectId] = pr - respM, err := p.listMemberships(ctx, projectId) - if err != nil { - pr.MembershipsErr = err - klog.Infof("Membership polling failed: %v", err) - } else { - pr.Memberships = respM.Resources - klog.Infof("Polling %s found %d memberships", projectId, len(respM.Resources)) - } - - respS, err := p.listScopes(ctx, projectId) - if err != nil { - pr.ScopesErr = err - klog.Infof("Scope polling failed: %v", err) - } else { - pr.Scopes = respS.Scopes - klog.Infof("Polling %s found %d scopes", projectId, len(respS.Scopes)) - } - - if pr.MembershipsErr != nil { - pr.BindingsErrs = []error{fmt.Errorf("Could not list bindings due to membership retrieval error")} - continue - } - - for _, mbr := range pr.Memberships { - respMB, err := p.listMembershipBindings(ctx, mbr.Name) - if err != nil { - pr.BindingsErrs = append(pr.BindingsErrs, err) - klog.Infof("MembershipBinding polling failed: %v", err) - } else { - pr.Bindings = append(pr.Bindings, respMB.MembershipBindings...) - klog.Infof("Polling %s found %d membership bindings", projectId, len(respMB.MembershipBindings)) - } - } - - } - return res -} - -func (p *Poller) listMemberships(ctx context.Context, projectId string) (*gkehubv1.ListMembershipsResponse, error) { - hubClient, err := gkehubv1.NewService(ctx) - if err != nil { - return nil, err - } - - parent := fmt.Sprintf("projects/%s/locations/global", projectId) - resp, err := hubClient.Projects.Locations.Memberships.List(parent).Do() - if err != nil { - return nil, err - } - - return resp, nil -} - -func (p *Poller) listScopes(ctx context.Context, projectId string) (*gkehubv1.ListScopesResponse, error) { - hubClient, err := gkehubv1.NewService(ctx) - if err != nil { - return nil, err - } - - parent := fmt.Sprintf("projects/%s/locations/global", projectId) - resp, err := hubClient.Projects.Locations.Scopes.List(parent).Do() - if err != nil { - return nil, err - } - - return resp, nil -} -func (p *Poller) listMembershipBindings(ctx context.Context, membership string) (*gkehubv1.ListMembershipBindingsResponse, error) { - hubClient, err := gkehubv1.NewService(ctx) - if err != nil { - return nil, err - } - - resp, err := hubClient.Projects.Locations.Memberships.Bindings.List(membership).Do() - if err != nil { - return nil, err - } - - return resp, nil -} diff --git a/controllers/main.go b/controllers/main.go index c84d141c..9d31a70e 100644 --- a/controllers/main.go +++ b/controllers/main.go @@ -1,4 +1,4 @@ -// Copyright 2022 The kpt and Nephio Authors +// Copyright 2022-2024 The kpt and Nephio Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -41,7 +41,6 @@ import ( "sigs.k8s.io/controller-runtime/pkg/healthz" "sigs.k8s.io/controller-runtime/pkg/reconcile" - "github.com/nephio-project/porch/controllers/fleetsyncs/pkg/controllers/fleetsync" "github.com/nephio-project/porch/controllers/packagevariants/pkg/controllers/packagevariant" "github.com/nephio-project/porch/controllers/packagevariantsets/pkg/controllers/packagevariantset" "github.com/nephio-project/porch/pkg/controllerrestmapper" @@ -52,7 +51,6 @@ var ( reconcilers = map[string]Reconciler{ "packagevariants": &packagevariant.PackageVariantReconciler{}, "packagevariantsets": &packagevariantset.PackageVariantSetReconciler{}, - "fleetsyncs": fleetsync.NewFleetSyncReconciler(), } )