Some updates

This commit is contained in:
Nikolai Rodionov 2024-04-05 17:40:20 +02:00
parent 1993d91624
commit 8305425d47
Signed by: allanger
GPG Key ID: 0AA46A90E25592AD
5 changed files with 72 additions and 4 deletions

View File

@ -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) { 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 return nil, nil
} }

View File

@ -1,4 +0,0 @@
provider: hetzner
servers:
- name: some name
kind: cax11

View File

@ -49,6 +49,7 @@ func (acc *Account) Create(ctx context.Context) error {
Labels: map[string]string{ Labels: map[string]string{
"username": acc.Data.Username, "username": acc.Data.Username,
"email-verified": "false", "email-verified": "false",
"managed-by": "softplayer",
}, },
}, },
} }

View File

@ -103,3 +103,38 @@ func (env *Environemnt) Create(ctx context.Context) error {
return nil 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
}

View File

@ -52,3 +52,10 @@ func WaitUntilCreated(ctx context.Context, client client.Client, obj client.Obje
} }
return nil 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
}