k8s.go 814 B

123456789101112131415161718192021222324252627282930313233343536373839
  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.ClusterRepository,
  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. cluster, err := repo.ReadCluster(uint(id))
  24. if err != nil {
  25. return err
  26. }
  27. kf.Cluster = cluster
  28. }
  29. return nil
  30. }