From 4d55bb1693c7be593fce5289128c1e77a8c6c209 Mon Sep 17 00:00:00 2001 From: aalexand Date: Tue, 9 Jul 2024 11:15:13 +0300 Subject: [PATCH] Add missing license headers --- cmd/sync/manager/manager.go | 1 + pkg/sync/parser/handler/cluster.go | 15 ++++++- .../parser/handler/managedcontrolplane.go | 45 +++++++++++++++++++ pkg/sync/parser/handler/types.go | 12 +++++ pkg/sync/parser/handler/util.go | 12 +++++ pkg/sync/parser/handler/vpc.go | 20 +++++++++ pkg/sync/parser/parser.go | 12 +++++ 7 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 pkg/sync/parser/handler/managedcontrolplane.go diff --git a/cmd/sync/manager/manager.go b/cmd/sync/manager/manager.go index f7923c5..1996f26 100644 --- a/cmd/sync/manager/manager.go +++ b/cmd/sync/manager/manager.go @@ -149,6 +149,7 @@ func main() { rp := parser.New(client, ctrlLog) rp.RegisterHandlerForGVK(schema.GroupVersionKind{Group: "ec2.services.k8s.aws", Version: "v1alpha1", Kind: "VPC"}, &handler.VPCHandler{}) rp.RegisterHandlerForGVK(schema.GroupVersionKind{Group: "cluster.x-k8s.io", Version: "v1beta1", Kind: "Cluster"}, &handler.ClusterHandler{}) + rp.RegisterHandlerForGVK(schema.GroupVersionKind{Group: "controlplane.cluster.x-k8s.io", Version: "v1beta2", Kind: "AWSManagedControlPlane"}, &handler.AWSManagedControlPlaneHandler{}) if err = (&manager.SyncController{ Client: client, diff --git a/pkg/sync/parser/handler/cluster.go b/pkg/sync/parser/handler/cluster.go index 270f238..2ffc771 100644 --- a/pkg/sync/parser/handler/cluster.go +++ b/pkg/sync/parser/handler/cluster.go @@ -1,3 +1,15 @@ +/* +Copyright 2024 Adobe. All rights reserved. +This file is licensed to you 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 REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + package handler import ( @@ -17,7 +29,7 @@ func (h *ClusterHandler) Handle(ctx context.Context, objects []unstructured.Unst targetObject := new(TargetObject) for _, obj := range objects { - clusterShortName, err := getNestedString(obj, "metadata", "labels", "shortName") + clusterShortName, err := getNestedString(obj, "metadata", "labels", "clusterShortName") if err != nil { return nil, err } @@ -46,7 +58,6 @@ func (h *ClusterHandler) Handle(ctx context.Context, objects []unstructured.Unst return nil, err } targetObject.Environment = environment - } return createTargetObjectPatch(targetObject) diff --git a/pkg/sync/parser/handler/managedcontrolplane.go b/pkg/sync/parser/handler/managedcontrolplane.go new file mode 100644 index 0000000..56f81ee --- /dev/null +++ b/pkg/sync/parser/handler/managedcontrolplane.go @@ -0,0 +1,45 @@ +/* +Copyright 2024 Adobe. All rights reserved. +This file is licensed to you 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 REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + +package handler + +import ( + "context" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "strings" +) + +// AWSManagedControlPlaneHandler extracts the following Cluster Registry metadata from AWSManagedControlPlane (CAPA) objects: +// - extra.oidcIssuer (e.g. "oidc.eks.us-west-2.amazonaws.com/id/EXAMPLED539D4633E2D5B6B716D3041E") +type AWSManagedControlPlaneHandler struct{} + +func (h *AWSManagedControlPlaneHandler) Handle(ctx context.Context, objects []unstructured.Unstructured) ([]byte, error) { + targetObject := new(TargetObject) + + for _, obj := range objects { + oidcProviderARN, err := getNestedString(obj, "status", "oidcProvider", "arn") + if err != nil { + return nil, err + } + targetObject.Extra.OidcIssuer = extractOIDCIssuerFromARN(oidcProviderARN) + } + + return createTargetObjectPatch(targetObject) +} + +func extractOIDCIssuerFromARN(arn string) string { + _, after, found := strings.Cut(arn, "/") + if !found { + return "" + } + return after +} diff --git a/pkg/sync/parser/handler/types.go b/pkg/sync/parser/handler/types.go index 9409ef5..89a4847 100644 --- a/pkg/sync/parser/handler/types.go +++ b/pkg/sync/parser/handler/types.go @@ -1,3 +1,15 @@ +/* +Copyright 2024 Adobe. All rights reserved. +This file is licensed to you 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 REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + package handler import ( diff --git a/pkg/sync/parser/handler/util.go b/pkg/sync/parser/handler/util.go index f030b61..aa66e5e 100644 --- a/pkg/sync/parser/handler/util.go +++ b/pkg/sync/parser/handler/util.go @@ -1,3 +1,15 @@ +/* +Copyright 2024 Adobe. All rights reserved. +This file is licensed to you 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 REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + package handler import ( diff --git a/pkg/sync/parser/handler/vpc.go b/pkg/sync/parser/handler/vpc.go index 441e829..21b5f6e 100644 --- a/pkg/sync/parser/handler/vpc.go +++ b/pkg/sync/parser/handler/vpc.go @@ -1,3 +1,15 @@ +/* +Copyright 2024 Adobe. All rights reserved. +This file is licensed to you 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 REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + package handler import ( @@ -10,6 +22,7 @@ import ( // virtualNetworks: // - vpcID (e.g. "vpc-0a1b2c3d4e5f6g7h8") // - cidrBlocks (e.g. ["10.123.0.0/12", "100.64.0.0/16]) +// - accountId (e.g. "123456789012") type VPCHandler struct{} func (h *VPCHandler) Handle(ctx context.Context, objects []unstructured.Unstructured) ([]byte, error) { @@ -30,6 +43,13 @@ func (h *VPCHandler) Handle(ctx context.Context, objects []unstructured.Unstruct ID: vpcID, Cidrs: cidrs, }) + + accountId, err := getNestedString(obj, "status", "ownerID") + if err != nil { + return nil, err + } + + targetObject.AccountID = accountId } return createTargetObjectPatch(targetObject) diff --git a/pkg/sync/parser/parser.go b/pkg/sync/parser/parser.go index 168f54d..7b0c654 100644 --- a/pkg/sync/parser/parser.go +++ b/pkg/sync/parser/parser.go @@ -1,3 +1,15 @@ +/* +Copyright 2024 Adobe. All rights reserved. +This file is licensed to you 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 REPRESENTATIONS +OF ANY KIND, either express or implied. See the License for the specific language +governing permissions and limitations under the License. +*/ + package parser import (