Skip to content

Commit

Permalink
add comments of each method in k8s package
Browse files Browse the repository at this point in the history
Signed-off-by: Burak Sekili <buraksekili@gmail.com>
  • Loading branch information
buraksekili committed Nov 7, 2023
1 parent 04e7b8a commit cef9a09
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 101 deletions.
98 changes: 0 additions & 98 deletions k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,101 +50,3 @@ func NewClient(conf *config.Config) (*Client, error) {

return cl, nil
}

//func (c *Client) RestartDashboardDeployment() error {
// config, err := rest.InClusterConfig()
// if err != nil {
// return err
// }
//
// clientset, err := kubernetes.NewForConfig(config)
// if err != nil {
// return err
// }
//
// if c.AppArgs.DashboardDeploymentName == "" {
// ls := metav1.LabelSelector{MatchLabels: map[string]string{
// data.TykBootstrapLabel: data.TykBootstrapDashboardDeployLabel,
// }}
//
// if c.AppArgs.ReleaseName != "" {
// ls.MatchLabels[data.TykBootstrapReleaseLabel] = c.AppArgs.ReleaseName
// }
//
// deployments, err := clientset.
// AppsV1().
// Deployments(c.AppArgs.ReleaseNamespace).
// List(
// context.TODO(),
// metav1.ListOptions{
// LabelSelector: labels.Set(ls.MatchLabels).String(),
// },
// )
// if err != nil {
// return errors.New(fmt.Sprintf("failed to list Tyk Dashboard Deployment, err: %v", err))
// }
//
// for _, deployment := range deployments.Items {
// c.AppArgs.DashboardDeploymentName = deployment.ObjectMeta.Name
// }
// }
//
// timeStamp := fmt.Sprintf(`{"spec": {"template": {"metadata": {"annotations": {"kubectl.kubernetes.io/restartedAt": "%s"}}}}}`,
// time.Now().Format("20060102150405"))
//
// _, err = clientset.
// AppsV1().
// Deployments(c.AppArgs.ReleaseName).
// Patch(
// context.TODO(),
// c.AppArgs.DashboardDeploymentName,
// types.StrategicMergePatchType,
// []byte(timeStamp),
// metav1.PatchOptions{},
// )
//
// return err
//}
//
//// discoverDashboardSvc lists Service objects with TykBootstrapReleaseLabel label that has
//// TykBootstrapDashboardSvcLabel value and gets this Service's metadata name, and port and
//// updates DashboardSvcName and DashboardSvcPort fields.
//func (c *Client) discoverDashboardSvc() error {
// ls := metav1.LabelSelector{MatchLabels: map[string]string{
// data.TykBootstrapLabel: data.TykBootstrapDashboardSvcLabel,
// }}
// if c.AppArgs.ReleaseName != "" {
// ls.MatchLabels[data.TykBootstrapReleaseLabel] = c.AppArgs.ReleaseName
// }
//
// l := labels.Set(ls.MatchLabels).String()
//
// services, err := c.clientSet.
// CoreV1().
// Services(c.AppArgs.ReleaseNamespace).
// List(context.TODO(), metav1.ListOptions{LabelSelector: l})
// if err != nil {
// return err
// }
//
// if len(services.Items) == 0 {
// return fmt.Errorf("failed to find services with label %v\n", l)
// }
//
// if len(services.Items) > 1 {
// fmt.Printf("[WARNING] Found multiple services with label %v\n", l)
// }
//
// service := services.Items[0]
// if len(service.Spec.Ports) == 0 {
// return fmt.Errorf("svc/%v/%v has no open ports\n", service.Name, service.Namespace)
// }
// if len(service.Spec.Ports) > 1 {
// fmt.Printf("[WARNING] Found multiple open ports in svc/%v/%v\n", service.Name, service.Namespace)
// }
//
// c.AppArgs.DashboardSvcPort = service.Spec.Ports[0].Port
// c.AppArgs.DashboardSvcName = service.Name
//
// return nil
//}
3 changes: 2 additions & 1 deletion k8s/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"tyk/tyk/bootstrap/pkg/constants"
)

// RestartDashboard restarts Tyk Dashboard Deployment.
func (c *Client) RestartDashboard() error {
if c.appArgs.K8s.DashboardDeploymentName == "" {
ls := metav1.LabelSelector{MatchLabels: map[string]string{
Expand Down Expand Up @@ -53,7 +54,7 @@ func (c *Client) RestartDashboard() error {
return err
}

// discoverDashboardSvc lists Service objects with constants.TykBootstrapReleaseLabel label that has
// discoverDashboardSvc lists Service objects with constants.TykBootstrapLabel label that has
// constants.TykBootstrapDashboardSvcLabel value and returns a service URL for Tyk Dashboard.
func (c *Client) discoverDashboardSvc() (string, error) {
ls := metav1.LabelSelector{MatchLabels: map[string]string{
Expand Down
6 changes: 6 additions & 0 deletions k8s/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const (
tykURLKey = "TYK_URL"
)

// BootstrapTykOperatorSecret bootstrap a Kubernetes Secret utilized by Tyk Operator.
// If the system has the secret created already, it deletes the existing one and recreates
// a secret for Tyk Operator.
func (c *Client) BootstrapTykOperatorSecret() error {
secrets, err := c.clientSet.
CoreV1().
Expand Down Expand Up @@ -67,6 +70,9 @@ func (c *Client) BootstrapTykOperatorSecret() error {
return nil
}

// BootstrapTykPortalSecret creates a secret required by Tyk Developer Portal pod which
// is not going to be ready until this secret is created. If there is a secret created already,
// it deletes the existing one and recreates the secret.
func (c *Client) BootstrapTykPortalSecret() error {
secrets, err := c.clientSet.
CoreV1().
Expand Down
5 changes: 3 additions & 2 deletions k8s/predelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// ExecutePreDeleteOperations executes operations needed in pre-delete chart hook one by one.
func (c *Client) ExecutePreDeleteOperations() error {
if err := c.deleteOperatorSecret(); err != nil {
return err
Expand All @@ -24,9 +25,8 @@ func (c *Client) ExecutePreDeleteOperations() error {
return nil
}

// deleteOperatorSecret deletes the Kubernetes secret created specifically for Tyk Operator.
func (c *Client) deleteOperatorSecret() error {
fmt.Println("Running pre delete hook")

secrets, err := c.clientSet.
CoreV1().
Secrets(c.appArgs.K8s.ReleaseNamespace).
Expand Down Expand Up @@ -64,6 +64,7 @@ func (c *Client) deleteOperatorSecret() error {
return nil
}

// deletePortalSecret deletes the Kubernetes secret created specifically for Tyk Developer Portal.
func (c *Client) deletePortalSecret() error {
fmt.Println("Running pre delete hook")

Expand Down
2 changes: 2 additions & 0 deletions k8s/readiness.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"time"
)

// CheckIfRequiredDeploymentsAreReady checks if the required Deployments are ready to be bootstrapped
// or not. At the moment, it checks for Redis and Tyk Dashboard pods to be ready.
func (c *Client) CheckIfRequiredDeploymentsAreReady() error {
time.Sleep(5 * time.Second)
var attemptCount int
Expand Down

0 comments on commit cef9a09

Please sign in to comment.