Skip to content

Commit

Permalink
use generics for ASO services
Browse files Browse the repository at this point in the history
  • Loading branch information
nojnhuh committed Sep 29, 2023
1 parent e21844c commit 5c4827d
Show file tree
Hide file tree
Showing 17 changed files with 1,016 additions and 639 deletions.
11 changes: 5 additions & 6 deletions azure/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ type Pauser interface {
// ServiceReconciler is an Azure service reconciler which can reconcile an Azure service.
type ServiceReconciler interface {
Name() string
IsManaged(ctx context.Context) (bool, error)
Reconciler
}

Expand Down Expand Up @@ -138,14 +137,14 @@ type ResourceSpecGetterWithHeaders interface {
}

// ASOResourceSpecGetter is an interface for getting all the required information to create/update/delete an Azure resource.
type ASOResourceSpecGetter interface {
type ASOResourceSpecGetter[T genruntime.MetaObject] interface {
// ResourceRef returns a concrete, named (and namespaced if applicable) ASO
// resource type to facilitate a strongly-typed GET.
ResourceRef() genruntime.MetaObject
ResourceRef() T
// Parameters returns a modified object if it points to a non-nil resource.
// Otherwise it returns a new value or nil if no updates are needed.
Parameters(ctx context.Context, object genruntime.MetaObject) (genruntime.MetaObject, error)
// Otherwise it returns an unmodified object if no updates are needed.
Parameters(ctx context.Context, existing T) (T, error)
// WasManaged returns whether or not the given resource was managed by a
// non-ASO-backed CAPZ and should be considered eligible for adoption.
WasManaged(genruntime.MetaObject) bool
WasManaged(T) bool
}
55 changes: 20 additions & 35 deletions azure/mock_azure/azure_mock.go

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

21 changes: 12 additions & 9 deletions azure/scope/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"strconv"
"strings"

asoresourcesv1 "github.com/Azure/azure-service-operator/v2/api/resources/v1api20200601"
"github.com/Azure/go-autorest/autorest"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -417,15 +418,17 @@ func (s *ClusterScope) SubnetSpecs() []azure.ResourceSpecGetter {
return subnetSpecs
}

// GroupSpec returns the resource group spec.
func (s *ClusterScope) GroupSpec() azure.ASOResourceSpecGetter {
return &groups.GroupSpec{
Name: s.ResourceGroup(),
Namespace: s.Namespace(),
Location: s.Location(),
ClusterName: s.ClusterName(),
AdditionalTags: s.AdditionalTags(),
Owner: *metav1.NewControllerRef(s.AzureCluster, infrav1.GroupVersion.WithKind("AzureCluster")),
// GroupSpecs returns the resource group spec.
func (s *ClusterScope) GroupSpecs() []azure.ASOResourceSpecGetter[*asoresourcesv1.ResourceGroup] {
return []azure.ASOResourceSpecGetter[*asoresourcesv1.ResourceGroup]{
&groups.GroupSpec{
Name: s.ResourceGroup(),
Namespace: s.Namespace(),
Location: s.Location(),
ClusterName: s.ClusterName(),
AdditionalTags: s.AdditionalTags(),
Owner: *metav1.NewControllerRef(s.AzureCluster, infrav1.GroupVersion.WithKind("AzureCluster")),
},

Check warning on line 431 in azure/scope/cluster.go

View check run for this annotation

Codecov / codecov/patch

azure/scope/cluster.go#L422-L431

Added lines #L422 - L431 were not covered by tests
}
}

Expand Down
21 changes: 12 additions & 9 deletions azure/scope/managedcontrolplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strings"
"time"

asoresourcesv1 "github.com/Azure/azure-service-operator/v2/api/resources/v1api20200601"
"github.com/Azure/go-autorest/autorest"
"github.com/pkg/errors"
"golang.org/x/mod/semver"
Expand Down Expand Up @@ -251,15 +252,17 @@ func (s *ManagedControlPlaneScope) Vnet() *infrav1.VnetSpec {
}
}

// GroupSpec returns the resource group spec.
func (s *ManagedControlPlaneScope) GroupSpec() azure.ASOResourceSpecGetter {
return &groups.GroupSpec{
Name: s.ResourceGroup(),
Namespace: s.Cluster.Namespace,
Location: s.Location(),
ClusterName: s.ClusterName(),
AdditionalTags: s.AdditionalTags(),
Owner: *metav1.NewControllerRef(s.ControlPlane, infrav1.GroupVersion.WithKind("AzureManagedControlPlane")),
// GroupSpecs returns the resource group spec.
func (s *ManagedControlPlaneScope) GroupSpecs() []azure.ASOResourceSpecGetter[*asoresourcesv1.ResourceGroup] {
return []azure.ASOResourceSpecGetter[*asoresourcesv1.ResourceGroup]{
&groups.GroupSpec{
Name: s.ResourceGroup(),
Namespace: s.Cluster.Namespace,
Location: s.Location(),
ClusterName: s.ClusterName(),
AdditionalTags: s.AdditionalTags(),
Owner: *metav1.NewControllerRef(s.ControlPlane, infrav1.GroupVersion.WithKind("AzureManagedControlPlane")),
},

Check warning on line 265 in azure/scope/managedcontrolplane.go

View check run for this annotation

Codecov / codecov/patch

azure/scope/managedcontrolplane.go#L256-L265

Added lines #L256 - L265 were not covered by tests
}
}

Expand Down
Loading

0 comments on commit 5c4827d

Please sign in to comment.