-
-
Notifications
You must be signed in to change notification settings - Fork 685
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): impl the app resources creation logic in controller (#351)
- Loading branch information
Showing
16 changed files
with
199 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,39 @@ | ||
package resourcer | ||
|
||
import ( | ||
"context" | ||
appv1 "github.com/labring/laf/controllers/application/api/v1" | ||
gatewayv1 "github.com/labring/laf/controllers/gateway/api/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
) | ||
|
||
func CreateGateway(ctx context.Context, c client.Client, schema *runtime.Scheme, app *appv1.Application) error { | ||
|
||
// Create a new gateway | ||
var gw gatewayv1.Gateway | ||
gw.Namespace = app.Namespace | ||
gw.Name = "gateway" | ||
gw.Labels = map[string]string{ | ||
"laf.dev/appid": app.Spec.AppId, | ||
} | ||
|
||
gw.Spec.AppId = app.Spec.AppId | ||
|
||
// TODO? may the gateway add region spec field | ||
// gw.Spec.Region = app.Spec.AppId | ||
|
||
if err := controllerutil.SetControllerReference(app, &gw, schema); err != nil { | ||
return err | ||
} | ||
err := c.Create(ctx, &gw) | ||
return err | ||
} | ||
|
||
func GetGateway(ctx context.Context, c client.Client, app *appv1.Application) (*gatewayv1.Gateway, error) { | ||
// Get the gateway | ||
var gw gatewayv1.Gateway | ||
err := c.Get(ctx, client.ObjectKey{Namespace: app.Namespace, Name: "gateway"}, &gw) | ||
return &gw, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,41 @@ | ||
package resourcer | ||
|
||
import ( | ||
"context" | ||
appv1 "github.com/labring/laf/controllers/application/api/v1" | ||
ossv1 "github.com/labring/laf/controllers/oss/api/v1" | ||
"github.com/labring/laf/pkg/common" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
) | ||
|
||
func CreateObjectStorageUser(ctx context.Context, c client.Client, schema *runtime.Scheme, app *appv1.Application) error { | ||
|
||
// Create a new oss user | ||
var oss ossv1.User | ||
oss.Namespace = app.Namespace | ||
oss.Name = "oss" | ||
oss.Labels = map[string]string{ | ||
"laf.dev/appid": app.Spec.AppId, | ||
} | ||
|
||
oss.Spec.Provider = "minio" | ||
oss.Spec.Region = app.Spec.Region | ||
oss.Spec.AppId = app.Spec.AppId | ||
oss.Spec.Password = common.GenerateAlphaNumericPassword(64) | ||
oss.Spec.Capacity.Storage = app.Status.BundleSpec.StorageCapacity | ||
|
||
if err := controllerutil.SetControllerReference(app, &oss, schema); err != nil { | ||
return err | ||
} | ||
err := c.Create(ctx, &oss) | ||
return err | ||
} | ||
|
||
func GetObjectStorageUser(ctx context.Context, c client.Client, app *appv1.Application) (*ossv1.User, error) { | ||
// Get the oss user | ||
var oss ossv1.User | ||
err := c.Get(ctx, client.ObjectKey{Namespace: app.Namespace, Name: "oss"}, &oss) | ||
return &oss, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.