k8s.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package forms
  2. import (
  3. "net/url"
  4. "strconv"
  5. "github.com/porter-dev/porter/internal/kubernetes"
  6. "github.com/porter-dev/porter/internal/repository"
  7. )
  8. // K8sForm is the generic base type for CRUD operations on k8s objects
  9. type K8sForm struct {
  10. *kubernetes.OutOfClusterConfig
  11. }
  12. // PopulateK8sOptionsFromQueryParams populates fields in the ReleaseForm using the passed
  13. // url.Values (the parsed query params)
  14. func (kf *K8sForm) PopulateK8sOptionsFromQueryParams(
  15. vals url.Values,
  16. repo repository.ServiceAccountRepository,
  17. ) error {
  18. if clusterID, ok := vals["cluster_id"]; ok && len(clusterID) == 1 {
  19. id, err := strconv.ParseUint(clusterID[0], 10, 64)
  20. if err != nil {
  21. return err
  22. }
  23. kf.ClusterID = uint(id)
  24. }
  25. if serviceAccountID, ok := vals["service_account_id"]; ok && len(serviceAccountID) == 1 {
  26. id, err := strconv.ParseUint(serviceAccountID[0], 10, 64)
  27. if err != nil {
  28. return err
  29. }
  30. sa, err := repo.ReadServiceAccount(uint(id))
  31. if err != nil {
  32. return err
  33. }
  34. kf.ServiceAccount = sa
  35. }
  36. return nil
  37. }