Skip to content

Commit

Permalink
feat: add AccountInfo subroutine and related configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
nexus49 committed Feb 25, 2025
1 parent f1af48a commit 7d491e5
Show file tree
Hide file tree
Showing 19 changed files with 698 additions and 1,113 deletions.
1 change: 1 addition & 0 deletions .testcoverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ exclude:
- api/v1alpha1 # skipping generated files and crd type definitions
- main\.go$ # skip covering main.go
- ^cmd # skip covering cmd directory
- ^pkg/testing/kcpenvtest # skip covering kcpenvtest
16 changes: 11 additions & 5 deletions api/v1alpha1/account_info_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ import (
type AccountInfoSpec struct {
FGA FGAInfo `json:"fga"`
Account AccountLocation `json:"account"`
ParentAccount *AccountLocation `json:"parentAccount"`
ParentAccount *AccountLocation `json:"parentAccount,omitempty"`
Organization AccountLocation `json:"organization"`
ClusterInfo ClusterInfo `json:"clusterInfo"`
}

type ClusterInfo struct {
CA string `json:"ca"`
}

type AccountLocation struct {
Name string `json:"name"`
ClusterId string `json:"clusterId"`
Path string `json:"path"`
URL string `json:"url"`
Type AccountType `json:"type"`
}

Expand All @@ -48,9 +54,9 @@ type AccountInfoStatus struct {
}

// +kubebuilder:object:root=true
// +kubebuilder:resource:path=accountinfos
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster
// +kubebuilder:resource:path=accountinfos
// Account is the Schema for the accounts API
type AccountInfo struct {
metav1.TypeMeta `json:",inline"`
Expand All @@ -62,13 +68,13 @@ type AccountInfo struct {

//+kubebuilder:object:root=true

// AccountLocationList contains a list of Account
type AccountLocationList struct {
// AccountInfoList contains a list of Account
type AccountInfoList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Account `json:"items"`
}

func init() {
SchemeBuilder.Register(&AccountInfo{}, &AccountLocationList{})
SchemeBuilder.Register(&AccountInfo{}, &AccountInfoList{})
}
80 changes: 48 additions & 32 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
listKind: AccountInfoList
plural: accountinfos
singular: accountinfo
scope: Namespaced
scope: Cluster
versions:
- name: v1alpha1
schema:
Expand Down Expand Up @@ -49,11 +49,21 @@ spec:
type: string
type:
type: string
url:
type: string
required:
- clusterId
- name
- path
- type
- url
type: object
clusterInfo:
properties:
ca:
type: string
required:
- ca
type: object
fga:
properties:
Expand All @@ -77,11 +87,14 @@ spec:
type: string
type:
type: string
url:
type: string
required:
- clusterId
- name
- path
- type
- url
type: object
parentAccount:
properties:
Expand All @@ -93,17 +106,20 @@ spec:
type: string
type:
type: string
url:
type: string
required:
- clusterId
- name
- path
- type
- url
type: object
required:
- account
- clusterInfo
- fga
- organization
- parentAccount
type: object
status:
description: AccountInfoStatus defines the observed state of Account
Expand Down
2 changes: 1 addition & 1 deletion config/resources/apiexport-core.openmfp.org.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ metadata:
spec:
latestResourceSchemas:
- v250220-cdcd05c.accounts.core.openmfp.org
- v250224-cafdd19.accountinfos.core.openmfp.org
- v250225-f1af48a.accountinfos.core.openmfp.org
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ apiVersion: apis.kcp.io/v1alpha1
kind: APIResourceSchema
metadata:
creationTimestamp: null
name: v250224-cafdd19.accountinfos.core.openmfp.org
name: v250225-f1af48a.accountinfos.core.openmfp.org
spec:
group: core.openmfp.org
names:
kind: AccountInfo
listKind: AccountInfoList
plural: accountinfos
singular: accountinfo
scope: Namespaced
scope: Cluster
versions:
- name: v1alpha1
schema:
Expand Down Expand Up @@ -46,11 +46,21 @@ spec:
type: string
type:
type: string
url:
type: string
required:
- clusterId
- name
- path
- type
- url
type: object
clusterInfo:
properties:
ca:
type: string
required:
- ca
type: object
fga:
properties:
Expand All @@ -74,11 +84,14 @@ spec:
type: string
type:
type: string
url:
type: string
required:
- clusterId
- name
- path
- type
- url
type: object
parentAccount:
properties:
Expand All @@ -90,17 +103,20 @@ spec:
type: string
type:
type: string
url:
type: string
required:
- clusterId
- name
- path
- type
- url
type: object
required:
- account
- clusterInfo
- fga
- organization
- parentAccount
type: object
status:
description: AccountInfoStatus defines the observed state of Account
Expand Down
3 changes: 3 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ type Config struct {
Workspace struct {
Enabled bool `envconfig:"default=true"`
}
AccountInfo struct {
Enabled bool `envconfig:"default=true"`
}
FGA struct {
Enabled bool `envconfig:"default=true"`
RootNamespace string `envconfig:"default=openmfp-root"`
Expand Down
10 changes: 5 additions & 5 deletions internal/controller/account_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (

corev1alpha1 "github.com/openmfp/account-operator/api/v1alpha1"
"github.com/openmfp/account-operator/internal/config"
"github.com/openmfp/account-operator/pkg/service"
"github.com/openmfp/account-operator/pkg/subroutines"
)

Expand All @@ -50,6 +49,10 @@ func NewAccountReconciler(log *logger.Logger, mgr ctrl.Manager, cfg config.Confi
if cfg.Subroutines.Workspace.Enabled {
subs = append(subs, subroutines.NewWorkspaceSubroutine(mgr.GetClient()))
}
if cfg.Subroutines.AccountInfo.Enabled {
subs = append(subs, subroutines.NewAccountInfoSubroutine(mgr.GetClient(), mgr.GetConfig().CAFile))
}
// The extensions subroutine is temporarily disabled in this release. It will be refactored and activated in a later release
//if cfg.Subroutines.Extension.Enabled {
// subs = append(subs, subroutines.NewExtensionSubroutine(mgr.GetClient()))
//}
Expand All @@ -68,11 +71,8 @@ func NewAccountReconciler(log *logger.Logger, mgr ctrl.Manager, cfg config.Confi
}
log.Debug().Msg("FGA client created")

srv := service.NewService(mgr.GetClient(), cfg.Subroutines.FGA.RootNamespace)

fgaClient := openfgav1.NewOpenFGAServiceClient(conn)

subs = append(subs, subroutines.NewFGASubroutine(mgr.GetClient(), fgaClient, srv, cfg.Subroutines.FGA.RootNamespace, cfg.Subroutines.FGA.CreatorRelation, cfg.Subroutines.FGA.ParentRelation, cfg.Subroutines.FGA.ObjectType))
subs = append(subs, subroutines.NewFGASubroutine(mgr.GetClient(), fgaClient, cfg.Subroutines.FGA.CreatorRelation, cfg.Subroutines.FGA.ParentRelation, cfg.Subroutines.FGA.ObjectType))
}
return &AccountReconciler{
lifecycle: lifecycle.NewLifecycleManager(log, operatorName, accountReconcilerName, mgr.GetClient(), subs).WithSpreadingReconciles().WithConditionManagement(),
Expand Down
Loading

0 comments on commit 7d491e5

Please sign in to comment.