openbao.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. Copyright © The ESO Authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. https://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package addon
  14. import (
  15. "crypto/rand"
  16. "fmt"
  17. "path/filepath"
  18. . "github.com/onsi/ginkgo/v2"
  19. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  20. "github.com/external-secrets/external-secrets-e2e/framework/util"
  21. )
  22. type OpenBao struct {
  23. chart *HelmChart
  24. Namespace string
  25. InClusterURL string
  26. LocalURL string
  27. RootToken string
  28. portForwarder *PortForward
  29. }
  30. func NewOpenBao() *OpenBao {
  31. rootToken := rand.Text()
  32. repo := "openbao"
  33. return &OpenBao{
  34. chart: &HelmChart{
  35. Namespace: "openbao",
  36. ReleaseName: "openbao",
  37. Chart: fmt.Sprintf("%s/openbao", repo),
  38. ChartVersion: "0.28.3",
  39. Repo: ChartRepo{
  40. Name: repo,
  41. URL: "https://openbao.github.io/openbao-helm",
  42. },
  43. Args: []string{
  44. "--create-namespace",
  45. },
  46. Values: []string{filepath.Join(AssetDir(), "openbao.values.yaml")},
  47. Vars: []StringTuple{{
  48. Key: "server.dev.devRootToken",
  49. Value: rootToken,
  50. }},
  51. },
  52. Namespace: "openbao",
  53. RootToken: rootToken,
  54. }
  55. }
  56. func (l *OpenBao) Install() error {
  57. if err := l.chart.Install(); err != nil {
  58. return err
  59. }
  60. if err := l.initBao(); err != nil {
  61. return err
  62. }
  63. return nil
  64. }
  65. func (l *OpenBao) initBao() error {
  66. err := util.WaitForPodsReady(l.chart.config.KubeClientSet, 1, l.Namespace, metav1.ListOptions{
  67. LabelSelector: "app.kubernetes.io/name=openbao",
  68. })
  69. if err != nil {
  70. return fmt.Errorf("error waiting for OpenBao to be ready: %w", err)
  71. }
  72. // This e2e test provider uses a local port-forwarded to talk to the OpenBao API instead
  73. // of using the kubernetes service. This allows us to run the e2e test suite locally.
  74. l.portForwarder, err = NewPortForward(l.chart.config.KubeClientSet, l.chart.config.KubeConfig, "openbao", l.chart.Namespace, 8200)
  75. if err != nil {
  76. return err
  77. }
  78. if err := l.portForwarder.Start(); err != nil {
  79. return err
  80. }
  81. l.InClusterURL = fmt.Sprintf("http://%s.%s.svc.cluster.local:8200", l.chart.ReleaseName, l.Namespace)
  82. l.LocalURL = fmt.Sprintf("http://localhost:%d", l.portForwarder.localPort)
  83. return nil
  84. }
  85. func (l *OpenBao) Logs() error {
  86. return l.chart.Logs()
  87. }
  88. func (l *OpenBao) Uninstall() error {
  89. if l.portForwarder != nil {
  90. l.portForwarder.Close()
  91. l.portForwarder = nil
  92. }
  93. if err := l.chart.Uninstall(); err != nil {
  94. return err
  95. }
  96. return l.chart.config.KubeClientSet.CoreV1().Namespaces().Delete(GinkgoT().Context(), l.chart.Namespace, metav1.DeleteOptions{})
  97. }
  98. func (l *OpenBao) Setup(cfg *Config) error {
  99. return l.chart.Setup(cfg)
  100. }