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

chore: pass in just enough args to ResolveProject #3233

Merged
merged 1 commit into from
Dec 3, 2024
Merged
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 apis/bigquery/v1beta1/dataset_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func NewBigQueryDatasetRef(ctx context.Context, reader client.Reader, obj *BigQu
id := &BigQueryDatasetRef{}

// Get Parent
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj, obj.Spec.ProjectRef)
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj.GetNamespace(), obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion apis/bigqueryanalyticshub/v1alpha1/listing_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func NewBigQueryAnalyticsHubListingRef(ctx context.Context, reader client.Reader
id := &BigQueryAnalyticsHubListingRef{}

// Get Parent
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj, obj.Spec.ProjectRef)
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj.GetNamespace(), obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion apis/bigqueryconnection/v1alpha1/connection_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
func NewBigQueryConnectionConnectionRef(ctx context.Context, reader client.Reader, obj *BigQueryConnectionConnection) (*BigQueryConnectionConnectionRef, error) {
id := &BigQueryConnectionConnectionRef{}

projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj, obj.Spec.ProjectRef)
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj.GetNamespace(), obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion apis/bigqueryconnection/v1beta1/connection_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
func NewBigQueryConnectionConnectionRef(ctx context.Context, reader client.Reader, obj *BigQueryConnectionConnection) (*BigQueryConnectionConnectionRef, error) {
id := &BigQueryConnectionConnectionRef{}

projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj, obj.Spec.ProjectRef)
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj.Namespace, obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion apis/discoveryengine/v1alpha1/datastore_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (r *DiscoveryEngineDataStoreRef) NormalizedExternal(ctx context.Context, re
// New builds a DiscoveryEngineDataStoreRef from the Config Connector DiscoveryEngineDataStore object.
func NewDiscoveryEngineDataStoreIDFromObject(ctx context.Context, reader client.Reader, obj *DiscoveryEngineDataStore) (*DiscoveryEngineDataStoreID, error) {
// Get Parent
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj, obj.Spec.ProjectRef)
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj.GetNamespace(), obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion apis/discoveryengine/v1alpha1/engine_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (r *DiscoveryEngineEngineRef) NormalizedExternal(ctx context.Context, reade
// New builds a DiscoveryEngineEngineRef from the Config Connector DiscoveryEngineEngine object.
func NewDiscoveryEngineEngineRef(ctx context.Context, reader client.Reader, obj *DiscoveryEngineEngine) (*DiscoveryEngineEngineID, error) {
// Get Parent
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj, obj.Spec.ProjectRef)
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj.GetNamespace(), obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion apis/kms/v1alpha1/keyhandle_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func NewKMSKeyHandleRef(ctx context.Context, reader client.Reader, obj *KMSKeyHa
id := &KMSKeyHandleRef{}

// Get Parent
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj, obj.Spec.ProjectRef)
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj.GetNamespace(), obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions apis/refs/v1beta1/projectref.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func ResolveProjectFromAnnotation(ctx context.Context, reader client.Reader, src
}

// ResolveProject will resolve a ProjectRef to a Project, with the ProjectID.
func ResolveProject(ctx context.Context, reader client.Reader, src client.Object, ref *ProjectRef) (*Project, error) {
func ResolveProject(ctx context.Context, reader client.Reader, otherNamespace string, ref *ProjectRef) (*Project, error) {
if ref == nil {
return nil, nil
}
Expand Down Expand Up @@ -103,7 +103,7 @@ func ResolveProject(ctx context.Context, reader client.Reader, src client.Object
Name: ref.Name,
}
if key.Namespace == "" {
key.Namespace = src.GetNamespace()
key.Namespace = otherNamespace
}

project := &unstructured.Unstructured{}
Expand Down Expand Up @@ -136,7 +136,7 @@ func ResolveProjectID(ctx context.Context, reader client.Reader, obj *unstructur
External: projectRefExternal,
}

project, err := ResolveProject(ctx, reader, obj, &projectRef)
project, err := ResolveProject(ctx, reader, obj.GetNamespace(), &projectRef)
if err != nil {
return "", fmt.Errorf("cannot parse projectRef.external %q in %v %v/%v: %w", projectRefExternal, obj.GetKind(), obj.GetNamespace(), obj.GetName(), err)
}
Expand All @@ -155,7 +155,7 @@ func ResolveProjectID(ctx context.Context, reader client.Reader, obj *unstructur
projectRef.Namespace = obj.GetNamespace()
}

project, err := ResolveProject(ctx, reader, obj, &projectRef)
project, err := ResolveProject(ctx, reader, obj.GetNamespace(), &projectRef)
if err != nil {
return "", fmt.Errorf("cannot parse projectRef in %v %v/%v: %w", obj.GetKind(), obj.GetNamespace(), obj.GetName(), err)
}
Expand Down
2 changes: 1 addition & 1 deletion apis/securesourcemanager/v1alpha1/instance_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func NewSecureSourceManagerInstanceRef(ctx context.Context, reader client.Reader
id := &SecureSourceManagerInstanceRef{}

// Get Parent
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj, obj.Spec.ProjectRef)
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj.GetNamespace(), obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion apis/securesourcemanager/v1alpha1/repository_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func NewSecureSourceManagerRepositoryRef(ctx context.Context, reader client.Read
id := &SecureSourceManagerRepositoryRef{}

// Get Parent
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj, obj.Spec.ProjectRef)
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj.GetNamespace(), obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion apis/workstations/v1alpha1/cluster_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func NewWorkstationClusterRef(ctx context.Context, reader client.Reader, obj *Wo
id := &WorkstationClusterRef{}

// Get Parent
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj, &obj.Spec.ProjectRef)
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj.GetNamespace(), &obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion apis/workstations/v1alpha1/config_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func NewWorkstationConfigRef(ctx context.Context, reader client.Reader, obj *Wor
id := &WorkstationConfigRef{}

// Get Parent
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj, obj.Spec.ProjectRef)
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj.GetNamespace(), obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion apis/workstations/v1beta1/cluster_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func NewWorkstationClusterRef(ctx context.Context, reader client.Reader, obj *Wo
id := &WorkstationClusterRef{}

// Get Parent
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj, &obj.Spec.ProjectRef)
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj.GetNamespace(), &obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion dev/tools/controllerbuilder/template/apis/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (p *{{.ProtoResource}}Parent) String() string {
func New{{.ProtoResource}}Identity(ctx context.Context, reader client.Reader, obj *{{.Kind}}) (*{{.ProtoResource}}Identity, error) {

// Get Parent
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj, obj.Spec.ProjectRef)
projectRef, err := refsv1beta1.ResolveProject(ctx, reader, obj.GetNamespace(), obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (m *model) AdapterForObject(ctx context.Context, reader client.Reader, u *u
return nil, fmt.Errorf("cannot resolve resource ID")
}

projectRef, err := refs.ResolveProject(ctx, reader, obj, obj.Spec.ProjectRef)
projectRef, err := refs.ResolveProject(ctx, reader, obj.GetNamespace(), obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (m *model) AdapterForObject(ctx context.Context, reader client.Reader, u *u
}

// Resolve Project Ref
projectRef, err := refv1beta1.ResolveProject(ctx, reader, obj, obj.Spec.ProjectRef)
projectRef, err := refv1beta1.ResolveProject(ctx, reader, obj.GetNamespace(), obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (m *model) AdapterForObject(ctx context.Context, reader client.Reader, u *u
return nil, fmt.Errorf("cannot resolve resource ID")
}

projectRef, err := refs.ResolveProject(ctx, reader, obj, &obj.Spec.ProjectRef)
projectRef, err := refs.ResolveProject(ctx, reader, obj.GetNamespace(), &obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/direct/cloudbuild/workerpool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (m *model) AdapterForObject(ctx context.Context, reader client.Reader, u *u
return nil, fmt.Errorf("cannot resolve resource ID")
}
// Get GCP Project
projectRef, err := refs.ResolveProject(ctx, reader, obj, obj.Spec.ProjectRef)
projectRef, err := refs.ResolveProject(ctx, reader, obj.GetNamespace(), obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/direct/common/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func normalizeResourceName(ctx context.Context, reader client.Reader, src client

switch ref.Kind {
case "Project":
project, err := refs.ResolveProject(ctx, reader, src, &refs.ProjectRef{
project, err := refs.ResolveProject(ctx, reader, src.GetNamespace(), &refs.ProjectRef{
Name: ref.Name,
Namespace: ref.Namespace,
External: ref.External,
Expand Down Expand Up @@ -167,7 +167,7 @@ func normalizeProjectRef(ctx context.Context, reader client.Reader, src client.O
return nil, nil
}

project, err := refs.ResolveProject(ctx, reader, src, ref)
project, err := refs.ResolveProject(ctx, reader, src.GetNamespace(), ref)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/direct/dataflow/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func normalizeProjectRef(ctx context.Context, reader client.Reader, src client.O
return nil, nil
}

project, err := refs.ResolveProject(ctx, reader, src, ref)
project, err := refs.ResolveProject(ctx, reader, src.GetNamespace(), ref)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/direct/dataform/repository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (m *model) AdapterForObject(ctx context.Context, reader client.Reader, u *u
return nil, fmt.Errorf("cannot resolve resource ID")
}

projectRef, err := apirefs.ResolveProject(ctx, reader, obj, obj.Spec.ProjectRef)
projectRef, err := apirefs.ResolveProject(ctx, reader, obj.GetNamespace(), obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (m *model) AdapterForObject(ctx context.Context, reader client.Reader, u *u
}

// Get Project ID
projectRef, err := refs.ResolveProject(ctx, reader, obj, &obj.Spec.ProjectRef)
projectRef, err := refs.ResolveProject(ctx, reader, obj.GetNamespace(), &obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (m *gkeHubModel) AdapterForObject(ctx context.Context, reader client.Reader
Namespace: obj.Spec.ProjectRef.Namespace,
External: obj.Spec.ProjectRef.External,
}
project, err := refs.ResolveProject(ctx, reader, obj, projectRef)
project, err := refs.ResolveProject(ctx, reader, u.GetNamespace(), projectRef)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (m *model) AdapterForObject(ctx context.Context, reader client.Reader, u *u
var keyProject *refs.Project
if obj.Spec.KeyProjectRef != nil {
var err error
keyProject, err = refs.ResolveProject(ctx, reader, obj, obj.Spec.KeyProjectRef)
keyProject, err = refs.ResolveProject(ctx, reader, obj.GetNamespace(), obj.Spec.KeyProjectRef)
if err != nil {
return nil, fmt.Errorf("unable to resolve key project for autokeyConfig naem: %s, err: %w", obj.GetName(), err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/direct/logging/logbucketref.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func LogBucketRef_ConvertToExternal(ctx context.Context, reader client.Reader, s
Namespace: obj.Spec.ProjectRef.Namespace,
External: obj.Spec.ProjectRef.External,
}
project, err := refs.ResolveProject(ctx, reader, loggingLogBucket, projectRef)
project, err := refs.ResolveProject(ctx, reader, loggingLogBucket.GetNamespace(), projectRef)
if err != nil {
return fmt.Errorf("cannot get project for referenced LoggingLogBucket %v: %w", key, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/direct/logging/logmetric_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (m *logMetricModel) AdapterForObject(ctx context.Context, reader client.Rea
return nil, fmt.Errorf("cannot resolve resource ID")
}

projectRef, err := refs.ResolveProject(ctx, reader, obj, &obj.Spec.ProjectRef)
projectRef, err := refs.ResolveProject(ctx, reader, obj.GetNamespace(), &obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (m *dashboardModel) AdapterForObject(ctx context.Context, kube client.Reade
return nil, fmt.Errorf("cannot resolve resource ID")
}

projectRef, err := refs.ResolveProject(ctx, kube, obj, &obj.Spec.ProjectRef)
projectRef, err := refs.ResolveProject(ctx, kube, obj.GetNamespace(), &obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/direct/networkconnectivity/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func normalizeProjectRef(ctx context.Context, reader client.Reader, src client.O
return nil, nil
}

project, err := refs.ResolveProject(ctx, reader, src, ref)
project, err := refs.ResolveProject(ctx, reader, src.GetNamespace(), ref)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (m *serviceConnectionPolicyModel) AdapterForObject(ctx context.Context, kub
return nil, fmt.Errorf("cannot resolve location")
}

projectRef, err := refs.ResolveProject(ctx, kube, obj, &obj.Spec.ProjectRef)
projectRef, err := refs.ResolveProject(ctx, kube, obj.GetNamespace(), &obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (m *caPoolModel) AdapterForObject(ctx context.Context, reader client.Reader
return nil, fmt.Errorf("cannot resolve location")
}

projectRef, err := refs.ResolveProject(ctx, reader, obj, refs.AsProjectRef(&obj.Spec.ProjectRef))
projectRef, err := refs.ResolveProject(ctx, reader, obj.GetNamespace(), refs.AsProjectRef(&obj.Spec.ProjectRef))
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func oneOfContainer(ctx context.Context, reader client.Reader, obj *krm.Privileg
container := ""
switch containerRef.(type) {
case *refs.ProjectRef:
project, err := refs.ResolveProject(ctx, reader, obj, projectRef)
project, err := refs.ResolveProject(ctx, reader, obj.GetNamespace(), projectRef)
if err != nil {
return "", err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (m *redisClusterModel) AdapterForObject(ctx context.Context, kube client.Re
return nil, fmt.Errorf("cannot resolve location")
}

projectRef, err := refs.ResolveProject(ctx, kube, obj, &obj.Spec.ProjectRef)
projectRef, err := refs.ResolveProject(ctx, kube, obj.GetNamespace(), &obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/direct/redis/cluster/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func normalizeProjectRef(ctx context.Context, reader client.Reader, src client.O
return nil, nil
}

project, err := refs.ResolveProject(ctx, reader, src, ref)
project, err := refs.ResolveProject(ctx, reader, src.GetNamespace(), ref)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/direct/workstations/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (m *modelWorkstationCluster) AdapterForObject(ctx context.Context, reader c
return nil, fmt.Errorf("cannot resolve resource ID")
}

projectRef, err := refs.ResolveProject(ctx, reader, obj, &obj.Spec.ProjectRef)
projectRef, err := refs.ResolveProject(ctx, reader, obj.GetNamespace(), &obj.Spec.ProjectRef)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/direct/workstations/cluster_normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NormalizeWorkstationCluster(ctx context.Context, kube client.Reader, obj *k
if obj.Spec.PrivateClusterConfig != nil && obj.Spec.PrivateClusterConfig.AllowedProjects != nil {
var resolvedProjects []refs.ProjectRef
for _, projectRef := range obj.Spec.PrivateClusterConfig.AllowedProjects {
resolvedProject, err := refs.ResolveProject(ctx, kube, obj, &projectRef)
resolvedProject, err := refs.ResolveProject(ctx, kube, obj.GetNamespace(), &projectRef)
if err != nil {
return err
}
Expand Down
Loading