Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic Update Crossplane Types to v0.15.0 #20

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "build"]
path = build
url = https://github.com/upbound/build
url = https://github.com/crossplane/build
2 changes: 1 addition & 1 deletion apis/core/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/akuityio/provider-crossplane-akuity
go 1.21

require (
github.com/akuity/api-client-go v0.15.0
github.com/akuity/grpc-gateway-client v0.0.0-20231116134900-80c401329778
github.com/avast/retry-go/v4 v4.5.1
github.com/crossplane/crossplane-runtime v1.14.3
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-2023110619213
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.31.0-20231106192134-1baebb0a1518.2/go.mod h1:xafc+XIsTxTy76GJQ1TKgvJWsSugFBqMaN27WhUblew=
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.15.0 h1:w9OPnQGiAMiXIZN0+eqN7Fph/u/g15H8Ug3/PCE/esA=
github.com/akuity/api-client-go v0.15.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
30 changes: 30 additions & 0 deletions internal/clients/akuity/mock/argocd_service_gateway_client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions internal/controller/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import (
"github.com/akuityio/provider-crossplane-akuity/internal/clients/kube"
"github.com/akuityio/provider-crossplane-akuity/internal/controller/config"
"github.com/akuityio/provider-crossplane-akuity/internal/features"
"github.com/akuityio/provider-crossplane-akuity/internal/reason"
"github.com/akuityio/provider-crossplane-akuity/internal/types"
"github.com/akuityio/provider-crossplane-akuity/internal/utils/pointer"
)
Expand Down Expand Up @@ -156,12 +155,15 @@ func (c *External) Observe(ctx context.Context, mg resource.Managed) (managed.Ex

akuityCluster, err := c.client.GetCluster(ctx, instanceID, meta.GetExternalName(managedCluster))
if err != nil {
if reason.IsNotFound(err) {
return managed.ExternalObservation{ResourceExists: false}, nil
}

managedCluster.SetConditions(xpv1.ReconcileError(err))
return managed.ExternalObservation{}, err
c.logger.Debug("As we are not able to differentiate PermissionDenied/NotFound when calling GetCluster, we simply treat as not found here", "error", err)
return managed.ExternalObservation{ResourceExists: false}, nil

// if reason.IsNotFound(err) {
// return managed.ExternalObservation{ResourceExists: false}, nil
// }
//
// managedCluster.SetConditions(xpv1.ReconcileError(err))
// return managed.ExternalObservation{}, err
}

actualCluster, err := types.AkuityAPIToCrossplaneCluster(instanceID, managedCluster.Spec.ForProvider, akuityCluster)
Expand Down
10 changes: 7 additions & 3 deletions internal/controller/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,13 @@ func TestObserve_GetClusterErr(t *testing.T) {
Return(nil, errors.New("fake")).Times(1)

resp, err := client.Observe(ctx, &managedCluster)
require.Error(t, err)
assert.Equal(t, managed.ExternalObservation{}, resp)
assert.Equal(t, xpv1.ReasonReconcileError, managedCluster.Status.Conditions[0].Reason)
// require.Error(t, err)
// assert.Equal(t, managed.ExternalObservation{}, resp)
// assert.Equal(t, xpv1.ReasonReconcileError, managedCluster.Status.Conditions[0].Reason)

// we use not found for permission denied error
require.NoError(t, err)
assert.Equal(t, managed.ExternalObservation{ResourceExists: false}, resp)
}

func TestObserve_HealthStatusNotHealthy(t *testing.T) {
Expand Down
60 changes: 44 additions & 16 deletions internal/types/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func AkuityAPIToCrossplaneClusterObservation(cluster *argocdv1.Cluster) (v1alpha
ID: cluster.GetId(),
Name: cluster.GetName(),
Description: cluster.GetDescription(),
Namespace: cluster.GetNamespace(),
NamespaceScoped: cluster.GetNamespaceScoped(),
Namespace: cluster.GetData().GetNamespace(),
NamespaceScoped: cluster.GetData().GetNamespaceScoped(),
Labels: cluster.GetData().GetLabels(),
Annotations: cluster.GetData().GetAnnotations(),
AutoUpgradeDisabled: cluster.GetData().GetAutoUpgradeDisabled(),
Expand Down Expand Up @@ -93,6 +93,28 @@ func AkuityAPIToClusterObservationAgentStateStatus(agentHealthStatuses map[strin
return statuses
}

func AkuityAPIToCrossplaneManagedClusterConfig(managedClusterConfig *argocdv1.ManagedClusterConfig) *generated.ManagedClusterConfig {
if managedClusterConfig == nil {
return nil
}

return &generated.ManagedClusterConfig{
SecretName: managedClusterConfig.GetSecretName(),
SecretKey: managedClusterConfig.GetSecretKey(),
}
}

func CrossplaneToAkuityAPIManagedClusterConfig(managedClusterConfig *generated.ManagedClusterConfig) *akuitytypes.ManagedClusterConfig {
if managedClusterConfig == nil {
return nil
}

return &akuitytypes.ManagedClusterConfig{
SecretName: managedClusterConfig.SecretName,
SecretKey: managedClusterConfig.SecretKey,
}
}

func AkuityAPIToCrossplaneCluster(instanceID string, managedCluster v1alpha1.ClusterParameters, cluster *argocdv1.Cluster) (v1alpha1.ClusterParameters, error) {
kustomizationYAML, err := AkuityAPIKustomizationToCrossplaneKustomization(cluster.GetData().GetKustomization())
if err != nil {
Expand Down Expand Up @@ -120,19 +142,22 @@ func AkuityAPIToCrossplaneCluster(instanceID string, managedCluster v1alpha1.Clu
Name: managedCluster.InstanceRef.Name,
},
Name: cluster.GetName(),
Namespace: cluster.GetNamespace(),
Namespace: cluster.GetData().GetNamespace(),
Labels: cluster.GetData().GetLabels(),
Annotations: cluster.GetData().GetAnnotations(),
ClusterSpec: generated.ClusterSpec{
Description: cluster.GetDescription(),
NamespaceScoped: cluster.GetNamespaceScoped(),
NamespaceScoped: cluster.GetData().GetNamespaceScoped(),
Data: generated.ClusterData{
Size: generated.ClusterSize(size),
AutoUpgradeDisabled: cluster.GetData().GetAutoUpgradeDisabled(),
Kustomization: string(kustomizationYAML),
AppReplication: cluster.GetData().GetAppReplication(),
TargetVersion: cluster.GetData().GetTargetVersion(),
RedisTunneling: cluster.GetData().GetRedisTunneling(),
Size: generated.ClusterSize(size),
AutoUpgradeDisabled: cluster.GetData().GetAutoUpgradeDisabled(),
Kustomization: string(kustomizationYAML),
AppReplication: cluster.GetData().GetAppReplication(),
TargetVersion: cluster.GetData().GetTargetVersion(),
RedisTunneling: cluster.GetData().GetRedisTunneling(),
DatadogAnnotationsEnabled: cluster.GetData().DatadogAnnotationsEnabled, //nolint:all
EksAddonEnabled: cluster.GetData().EksAddonEnabled, //nolint:all
ManagedClusterConfig: AkuityAPIToCrossplaneManagedClusterConfig(cluster.GetData().GetManagedClusterConfig()),
},
},
EnableInClusterKubeConfig: managedCluster.EnableInClusterKubeConfig,
Expand Down Expand Up @@ -169,12 +194,15 @@ func CrossplaneToAkuityAPICluster(cluster v1alpha1.ClusterParameters) (akuitytyp
Description: cluster.ClusterSpec.Description,
NamespaceScoped: cluster.ClusterSpec.NamespaceScoped,
Data: akuitytypes.ClusterData{
Size: akuitytypes.ClusterSize(cluster.ClusterSpec.Data.Size),
AutoUpgradeDisabled: &cluster.ClusterSpec.Data.AutoUpgradeDisabled,
Kustomization: kustomization,
AppReplication: &cluster.ClusterSpec.Data.AppReplication,
TargetVersion: cluster.ClusterSpec.Data.TargetVersion,
RedisTunneling: &cluster.ClusterSpec.Data.RedisTunneling,
Size: akuitytypes.ClusterSize(cluster.ClusterSpec.Data.Size),
AutoUpgradeDisabled: &cluster.ClusterSpec.Data.AutoUpgradeDisabled,
Kustomization: kustomization,
AppReplication: &cluster.ClusterSpec.Data.AppReplication,
TargetVersion: cluster.ClusterSpec.Data.TargetVersion,
RedisTunneling: &cluster.ClusterSpec.Data.RedisTunneling,
DatadogAnnotationsEnabled: cluster.ClusterSpec.Data.DatadogAnnotationsEnabled,
EksAddonEnabled: cluster.ClusterSpec.Data.EksAddonEnabled,
ManagedClusterConfig: CrossplaneToAkuityAPIManagedClusterConfig(cluster.ClusterSpec.Data.ManagedClusterConfig),
},
},
}, nil
Expand Down
4 changes: 2 additions & 2 deletions internal/types/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func TestAkuityAPIToCrossplaneClusterObservation(t *testing.T) {
ID: fixtures.ArgocdCluster.GetId(),
Name: fixtures.ArgocdCluster.GetName(),
Description: fixtures.ArgocdCluster.GetDescription(),
Namespace: fixtures.ArgocdCluster.GetNamespace(),
NamespaceScoped: fixtures.ArgocdCluster.GetNamespaceScoped(),
Namespace: fixtures.ArgocdCluster.GetData().GetNamespace(),
NamespaceScoped: fixtures.ArgocdCluster.GetData().GetNamespaceScoped(),
Labels: fixtures.ArgocdCluster.GetData().GetLabels(),
Annotations: fixtures.ArgocdCluster.GetData().GetAnnotations(),
AutoUpgradeDisabled: fixtures.ArgocdCluster.GetData().GetAutoUpgradeDisabled(),
Expand Down
60 changes: 39 additions & 21 deletions internal/types/generated/akuity/v1alpha1/argocdinstance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,46 +47,64 @@ type ArgoCDExtensionInstallEntry struct {
}

type ClusterCustomization struct {
AutoUpgradeDisabled bool `json:"autoUpgradeDisabled,omitempty"`
AutoUpgradeDisabled *bool `json:"autoUpgradeDisabled,omitempty"`
Kustomization runtime.RawExtension `json:"kustomization,omitempty"`
AppReplication bool `json:"appReplication,omitempty"`
RedisTunneling bool `json:"redisTunneling,omitempty"`
AppReplication *bool `json:"appReplication,omitempty"`
RedisTunneling *bool `json:"redisTunneling,omitempty"`
}

type AppsetPolicy struct {
Policy string `json:"policy,omitempty"`
OverridePolicy bool `json:"overridePolicy,omitempty"`
OverridePolicy *bool `json:"overridePolicy,omitempty"`
}

type AgentPermissionsRule struct {
ApiGroups []string `json:"apiGroups,omitempty"`
Resources []string `json:"resources,omitempty"`
Verbs []string `json:"verbs,omitempty"`
}

type CrossplaneExtensionResource struct {
Group string `json:"group,omitempty"`
}

type CrossplaneExtension struct {
Resources []*CrossplaneExtensionResource `json:"resources,omitempty"`
}

type InstanceSpec struct {
IpAllowList []*IPAllowListEntry `json:"ipAllowList,omitempty"`
Subdomain string `json:"subdomain,omitempty"`
DeclarativeManagementEnabled bool `json:"declarativeManagementEnabled,omitempty"`
Extensions []*ArgoCDExtensionInstallEntry `json:"extensions,omitempty"`
ClusterCustomizationDefaults *ClusterCustomization `json:"clusterCustomizationDefaults,omitempty"`
ImageUpdaterEnabled bool `json:"imageUpdaterEnabled,omitempty"`
BackendIpAllowListEnabled bool `json:"backendIpAllowListEnabled,omitempty"`
RepoServerDelegate *RepoServerDelegate `json:"repoServerDelegate,omitempty"`
AuditExtensionEnabled bool `json:"auditExtensionEnabled,omitempty"`
SyncHistoryExtensionEnabled bool `json:"syncHistoryExtensionEnabled,omitempty"`
ImageUpdaterDelegate *ImageUpdaterDelegate `json:"imageUpdaterDelegate,omitempty"`
AppSetDelegate *AppSetDelegate `json:"appSetDelegate,omitempty"`
AssistantExtensionEnabled bool `json:"assistantExtensionEnabled,omitempty"`
AppsetPolicy *AppsetPolicy `json:"appsetPolicy,omitempty"`
HostAliases []*HostAliases `json:"hostAliases,omitempty"`
IpAllowList []*IPAllowListEntry `json:"ipAllowList,omitempty"`
Subdomain string `json:"subdomain,omitempty"`
DeclarativeManagementEnabled *bool `json:"declarativeManagementEnabled,omitempty"`
Extensions []*ArgoCDExtensionInstallEntry `json:"extensions,omitempty"`
ClusterCustomizationDefaults *ClusterCustomization `json:"clusterCustomizationDefaults,omitempty"`
ImageUpdaterEnabled *bool `json:"imageUpdaterEnabled,omitempty"`
BackendIpAllowListEnabled *bool `json:"backendIpAllowListEnabled,omitempty"`
RepoServerDelegate *RepoServerDelegate `json:"repoServerDelegate,omitempty"`
AuditExtensionEnabled *bool `json:"auditExtensionEnabled,omitempty"`
SyncHistoryExtensionEnabled *bool `json:"syncHistoryExtensionEnabled,omitempty"`
CrossplaneExtension *CrossplaneExtension `json:"crossplaneExtension,omitempty"`
ImageUpdaterDelegate *ImageUpdaterDelegate `json:"imageUpdaterDelegate,omitempty"`
AppSetDelegate *AppSetDelegate `json:"appSetDelegate,omitempty"`
AssistantExtensionEnabled *bool `json:"assistantExtensionEnabled,omitempty"`
AppsetPolicy *AppsetPolicy `json:"appsetPolicy,omitempty"`
HostAliases []*HostAliases `json:"hostAliases,omitempty"`
AgentPermissionsRules []*AgentPermissionsRule `json:"agentPermissionsRules,omitempty"`
Fqdn *string `json:"fqdn,omitempty"`
MultiClusterK8SDashboardEnabled *bool `json:"multiClusterK8sDashboardEnabled,omitempty"`
}

type ManagedCluster struct {
ClusterName string `json:"clusterName,omitempty"`
}

type RepoServerDelegate struct {
ControlPlane bool `json:"controlPlane,omitempty"`
ControlPlane *bool `json:"controlPlane,omitempty"`
ManagedCluster *ManagedCluster `json:"managedCluster,omitempty"`
}

type ImageUpdaterDelegate struct {
ControlPlane bool `json:"controlPlane,omitempty"`
ControlPlane *bool `json:"controlPlane,omitempty"`
ManagedCluster *ManagedCluster `json:"managedCluster,omitempty"`
}

Expand Down
Loading
Loading