k8s.go 924 B

1234567891011121314151617181920212223242526272829303132333435
  1. package forms
  2. import (
  3. "net/url"
  4. "github.com/porter-dev/porter/internal/kubernetes"
  5. "github.com/porter-dev/porter/internal/repository"
  6. )
  7. // K8sForm is the generic base type for CRUD operations on k8s objects
  8. type K8sForm struct {
  9. *kubernetes.OutOfClusterConfig
  10. }
  11. // PopulateK8sOptionsFromQueryParams populates fields in the ReleaseForm using the passed
  12. // url.Values (the parsed query params)
  13. func (kf *K8sForm) PopulateK8sOptionsFromQueryParams(vals url.Values) {
  14. if context, ok := vals["context"]; ok && len(context) == 1 {
  15. kf.Context = context[0]
  16. }
  17. }
  18. // PopulateK8sOptionsFromUserID uses the passed userID to populate the HelmOptions object
  19. func (kf *K8sForm) PopulateK8sOptionsFromUserID(userID uint, repo repository.UserRepository) error {
  20. user, err := repo.ReadUser(userID)
  21. if err != nil {
  22. return err
  23. }
  24. kf.AllowedContexts = user.ContextToSlice()
  25. kf.KubeConfig = user.RawKubeConfig
  26. return nil
  27. }