Skip to content

Commit

Permalink
Add missing license headers
Browse files Browse the repository at this point in the history
  • Loading branch information
aalexand committed Jul 9, 2024
1 parent f640275 commit 4d55bb1
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/sync/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 13 additions & 2 deletions pkg/sync/parser/handler/cluster.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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
}
Expand Down Expand Up @@ -46,7 +58,6 @@ func (h *ClusterHandler) Handle(ctx context.Context, objects []unstructured.Unst
return nil, err
}
targetObject.Environment = environment

}

return createTargetObjectPatch(targetObject)
Expand Down
45 changes: 45 additions & 0 deletions pkg/sync/parser/handler/managedcontrolplane.go
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 12 additions & 0 deletions pkg/sync/parser/handler/types.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
12 changes: 12 additions & 0 deletions pkg/sync/parser/handler/util.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
20 changes: 20 additions & 0 deletions pkg/sync/parser/handler/vpc.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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) {
Expand All @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions pkg/sync/parser/parser.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down

0 comments on commit 4d55bb1

Please sign in to comment.