Some updates
This commit is contained in:
parent
1993d91624
commit
8305425d47
@ -60,6 +60,35 @@ func (e *EnvironmentsServer) Update(ctx context.Context, in *proto.EnvironmentFu
|
||||
}
|
||||
|
||||
func (e *EnvironmentsServer) Delete(ctx context.Context, in *proto.EnvironmentFull) (*empty.Empty, error) {
|
||||
md, ok := metadata.FromIncomingContext(ctx)
|
||||
if !ok {
|
||||
return nil, errors.New("metadata is not provided")
|
||||
}
|
||||
token, ok := md["token"]
|
||||
if !ok {
|
||||
return nil, errors.New("token is not sent via metadata")
|
||||
}
|
||||
|
||||
uuid, ok := md["uuid"]
|
||||
if !ok {
|
||||
return nil, errors.New("used id is not sent via metadata")
|
||||
}
|
||||
|
||||
data := &controllers.EnvironemntData{
|
||||
Name: in.Data.GetName(),
|
||||
Provider: in.Data.GetProvider().String(),
|
||||
Kubernetes: in.Data.GetKubernetes().String(),
|
||||
}
|
||||
environment := &controllers.Environemnt{
|
||||
UserID: uuid[0],
|
||||
Controller: e.controller,
|
||||
Data: data,
|
||||
Token: token[0],
|
||||
}
|
||||
err := environment.Create(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
@ -1,4 +0,0 @@
|
||||
provider: hetzner
|
||||
servers:
|
||||
- name: some name
|
||||
kind: cax11
|
@ -49,6 +49,7 @@ func (acc *Account) Create(ctx context.Context) error {
|
||||
Labels: map[string]string{
|
||||
"username": acc.Data.Username,
|
||||
"email-verified": "false",
|
||||
"managed-by": "softplayer",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -103,3 +103,38 @@ func (env *Environemnt) Create(ctx context.Context) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (env *Environemnt) Delete(ctx context.Context) error {
|
||||
env.Controller.GetClient()
|
||||
conf := &rest.Config{
|
||||
Host: "https://kubernetes.default.svc.cluster.local:443",
|
||||
BearerToken: env.Token,
|
||||
TLSClientConfig: rest.TLSClientConfig{
|
||||
Insecure: true,
|
||||
},
|
||||
}
|
||||
|
||||
controller, err := ctrl.NewManager(conf, ctrl.Options{})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
obj := corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: env.Data.Name,
|
||||
Namespace: env.UserID,
|
||||
Labels: map[string]string{
|
||||
"component": "bootstrap",
|
||||
},
|
||||
},
|
||||
Data: map[string]string{
|
||||
"vars": env.Data.buildVars(),
|
||||
},
|
||||
}
|
||||
if err := kube.Delete(ctx, controller.GetClient(), &obj, false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -52,3 +52,10 @@ func WaitUntilCreated(ctx context.Context, client client.Client, obj client.Obje
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func Delete(ctx context.Context, client client.Client, obj client.Object, wait bool) error {
|
||||
if err := client.Delete(ctx, obj); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user