Skip to content

Commit

Permalink
add agentPermissionsRules, fqdn, CrossplaneExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
imwithye committed Jul 4, 2024
1 parent 8e0ca98 commit 20ce077
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
)

require (
github.com/akuity/api-client-go v0.14.0 // indirect
github.com/alevinval/sse v1.0.2 // indirect
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
github.com/go-resty/resty/v2 v2.11.0 // indirect
Expand All @@ -33,7 +34,6 @@ require (

require (
dario.cat/mergo v1.0.0 // indirect
github.com/akuity/api-client-go v0.10.0
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20231202071711-9a357b53e9c9 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/akuity/api-client-go v0.10.0 h1:v38/8a1e1abOkLzpVflytraAcUX0UGDRIum8W7luqBY=
github.com/akuity/api-client-go v0.10.0/go.mod h1:F9Rdem0OdJQ+JLsO2I76jyrFFypK9JhgjnlLUve2KU0=
github.com/akuity/api-client-go v0.14.0 h1:kD+I4wTPPoj0gZx+/bLHeTfW+9LTtDFw6HpQNV1HGwg=
github.com/akuity/api-client-go v0.14.0/go.mod h1:ziHCeqFmAytZZ6lZbwvmq9hFG42bLV8iHnz13/SdMoo=
github.com/akuity/grpc-gateway-client v0.0.0-20231116134900-80c401329778 h1:qj3+B4PU5AR2mBffDVXvP2d3hLCNDot28KKPWvQnOxs=
github.com/akuity/grpc-gateway-client v0.0.0-20231116134900-80c401329778/go.mod h1:0MZqOxL+zq+hGedAjYhkm1tOKuZyjUmE/xA8nqXa9q0=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
Expand Down
46 changes: 46 additions & 0 deletions internal/types/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,14 @@ func AkuityAPIToCrossplaneInstanceSpec(instanceSpec *argocdv1.InstanceSpec) (cro
RepoServerDelegate: AkuityAPIToCrossplaneRepoServerDelegate(instanceSpec.GetRepoServerDelegate()),
AuditExtensionEnabled: instanceSpec.GetAuditExtensionEnabled(),
SyncHistoryExtensionEnabled: instanceSpec.GetSyncHistoryExtensionEnabled(),
CrossplaneExtension: AkuityAPIToCrossplaneCrossplaneExtension(instanceSpec.CrossplaneExtension),
ImageUpdaterDelegate: AkuityAPIToCrossplaneImageUpdaterDelegate(instanceSpec.GetImageUpdaterDelegate()),
AppSetDelegate: AkuityAPIToCrossplaneAppSetDelegate(instanceSpec.GetAppSetDelegate()),
AssistantExtensionEnabled: instanceSpec.GetAssistantExtensionEnabled(),
AppsetPolicy: AkuityAPIToCrossplaneAppsetPolicy(instanceSpec.GetAppsetPolicy()),
HostAliases: AkuityAPIToCrossplaneHostAliases(instanceSpec.GetHostAliases()),
AgentPermissionsRules: AkuityAPIToCrossplaneAgentPermissionsRules(instanceSpec.GetAgentPermissionsRules()),
Fqdn: instanceSpec.GetFqdn(),
}, nil
}

Expand Down Expand Up @@ -416,6 +419,21 @@ func AkuityAPIToCrossplaneRepoServerDelegate(repoServerDelegate *argocdv1.RepoSe
}
}

func AkuityAPIToCrossplaneCrossplaneExtension(crossplaneExtension *argocdv1.CrossplaneExtension) *crossplanetypes.CrossplaneExtension {
if crossplaneExtension == nil {
return nil
}

resources := make([]*crossplanetypes.CrossplaneExtensionResource, 0, len(crossplaneExtension.Resources))
for _, r := range crossplaneExtension.Resources {
resource := &crossplanetypes.CrossplaneExtensionResource{
Group: r.Group,
}
resources = append(resources, resource)
}
return &crossplanetypes.CrossplaneExtension{Resources: resources}
}

func AkuityAPIToCrossplaneImageUpdaterDelegate(imageUpdaterDelegate *argocdv1.ImageUpdaterDelegate) *crossplanetypes.ImageUpdaterDelegate {
if imageUpdaterDelegate == nil {
return nil
Expand Down Expand Up @@ -469,6 +487,34 @@ func AkuityAPIToCrossplaneHostAliases(hostAliasesList []*argocdv1.HostAliases) [
return crossplaneHostAliasesList
}

func AkuityAPIToCrossplaneAgentPermissionsRules(agentPermissionsRules []*argocdv1.AgentPermissionsRule) []*crossplanetypes.AgentPermissionsRule {
if len(agentPermissionsRules) == 0 {
return nil
}

crossplaneAgentPermissionsRules := make([]*crossplanetypes.AgentPermissionsRule, 0, len(agentPermissionsRules))
for _, rule := range agentPermissionsRules {
var apiGroups []string
for _, apiGroup := range rule.ApiGroups {
apiGroups = append(apiGroups, apiGroup)
}
var resources []string
for _, resource := range rule.Resources {
resources = append(resources, resource)
}
var verbs []string
for _, verb := range rule.Verbs {
verbs = append(verbs, verb)
}
crossplaneAgentPermissionsRules = append(crossplaneAgentPermissionsRules, &crossplanetypes.AgentPermissionsRule{
ApiGroups: apiGroups,
Resources: resources,
Verbs: verbs,
})
}
return crossplaneAgentPermissionsRules
}

func CrossplaneToAkuityAPIArgoCD(name string, instance *crossplanetypes.ArgoCD) (*structpb.Struct, error) {
instanceSpec, err := CrossplaneToAkuityAPIInstanceSpec(instance.Spec.InstanceSpec)
if err != nil {
Expand Down

0 comments on commit 20ce077

Please sign in to comment.