Skip to content

Commit 6b6f882

Browse files
committed
Add createCompany feature
1 parent 9545d8b commit 6b6f882

File tree

10 files changed

+53
-42
lines changed

10 files changed

+53
-42
lines changed

api/core/v1alpha1/company_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type CompanySpec struct {
3030

3131
// Foo is an example field of Company. Edit company_types.go to remove/update
3232
Name string `json:"name"`
33+
Description string `json:"description,omitempty"`
3334
CompanyOwners []string `json:"companyOwners,omitempty"`
3435
ConsoleRef NamespacedName `json:"consoleRef"`
3536
// Clusters []string `json:"companyOwners"`

config/rbac/role.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ kind: ClusterRole
44
metadata:
55
name: manager-role
66
rules:
7+
- apiGroups:
8+
- ""
9+
resources:
10+
- secrets
11+
verbs:
12+
- get
13+
- list
14+
- watch
715
- apiGroups:
816
- core.mia-platform.eu
917
resources:
@@ -30,3 +38,11 @@ rules:
3038
- get
3139
- patch
3240
- update
41+
- apiGroups:
42+
- core.mia-platform.eu
43+
resources:
44+
- console
45+
verbs:
46+
- get
47+
- list
48+
- watch

deployments/operator/crds/core.mia-platform.eu_companies.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ spec:
5353
- name
5454
- namespace
5555
type: object
56+
description:
57+
type: string
5658
name:
5759
description: Foo is an example field of Company. Edit company_types.go
5860
to remove/update

deployments/operator/files/console-operator-company-controller-ClusterRole.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
rules:
2+
- apiGroups:
3+
- ""
4+
resources:
5+
- secrets
6+
verbs:
7+
- get
8+
- list
9+
- watch
210
- apiGroups:
311
- core.mia-platform.eu
412
resources:
@@ -25,3 +33,11 @@ rules:
2533
- get
2634
- patch
2735
- update
36+
- apiGroups:
37+
- core.mia-platform.eu
38+
resources:
39+
- console
40+
verbs:
41+
- get
42+
- list
43+
- watch

pkg/company-controller/company_controller.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ type CompanyReconciler struct {
3838
}
3939

4040
// +kubebuilder:rbac:groups=core.mia-platform.eu,resources=companies,verbs=get;list;watch;create;update;patch;delete
41+
// +kubebuilder:rbac:groups=core.mia-platform.eu,resources=console,verbs=get;list;watch
4142
// +kubebuilder:rbac:groups=core.mia-platform.eu,resources=companies/status,verbs=get;update;patch
4243
// +kubebuilder:rbac:groups=core.mia-platform.eu,resources=companies/finalizers,verbs=update
4344

45+
// +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch
46+
4447
func (r *CompanyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
4548
log := ctrl.LoggerFrom(ctx, "company", req.NamespacedName)
4649
ctx = ctrl.LoggerInto(ctx, log)
@@ -119,10 +122,19 @@ func (r *CompanyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
119122

120123
if exists {
121124
log.Info("Company already exists", "companyName", companyName)
122-
} else {
123-
log.Info("Company does not exist", "companyName", companyName)
125+
return ctrl.Result{}, nil
126+
}
127+
128+
newCompany := consoleclient.ConsoleCompany{
129+
Name: companyName,
130+
Description: company.Spec.Description,
131+
}
132+
if err := consoleClient.CreateCompany(ctx, newCompany); err != nil {
133+
log.Error(err, "failed to create company in Console", "companyName", companyName)
134+
return ctrl.Result{}, err
124135
}
125136

137+
log.Info("Company created successfully in Console", "companyName", companyName)
126138
return ctrl.Result{}, nil
127139
}
128140

pkg/console-client/console_client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ func (c *Client) CompanyExists(ctx context.Context, companyName string) (bool, e
192192
return false, nil
193193
}
194194

195+
func (c *Client) CreateCompany(ctx context.Context, company ConsoleCompany) error {
196+
return c.PostJSON(ctx, "/api/backend/tenants", company, nil)
197+
}
198+
195199
// PostJSON is a convenience method that performs POST and unmarshals JSON response
196200
func (c *Client) PostJSON(ctx context.Context, endpoint string, body interface{}, result interface{}) error {
197201
resp, err := c.Post(ctx, endpoint, body)

pkg/console-client/console_client_models.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ type TokenResponse struct {
4545
}
4646

4747
type ConsoleCompany struct {
48-
ID string `json:"id"`
4948
Name string `json:"name"`
5049
Description string `json:"description,omitempty"`
5150
// Add other fields as needed based on your API response

test/static/console-demo.console.yaml

Lines changed: 0 additions & 15 deletions
This file was deleted.

test/static/demo-live.company.yaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/static/fake-company.company.yaml

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)