Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple fixes for operator plugin #422

Merged
merged 1 commit into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions kubectl-minio/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func (o *operatorInitCmd) run() error {
sa := resources.NewServiceAccountForOperator(helpers.DefaultServiceAccount, o.operatorOpts.NS)
crb := resources.NewCluterRoleBindingForOperator(helpers.DefaultServiceAccount, o.operatorOpts.NS)
d := resources.NewDeploymentForOperator(o.operatorOpts)
svc := resources.NewServiceForOperator(o.operatorOpts)

if !o.output {
path, _ := rootCmd.Flags().GetString(kubeconfig)
Expand All @@ -109,6 +110,9 @@ func (o *operatorInitCmd) run() error {
if err = createClusterRB(client, crb); err != nil {
return err
}
if err = createService(client, svc); err != nil {
return err
}
return createDeployment(client, d)
}

Expand Down Expand Up @@ -183,3 +187,15 @@ func createDeployment(client *kubernetes.Clientset, d *appsv1.Deployment) error
fmt.Printf("MinIO Operator Deployment %s: created\n", d.ObjectMeta.Name)
return nil
}

func createService(client *kubernetes.Clientset, svc *corev1.Service) error {
_, err := client.CoreV1().Services(svc.ObjectMeta.Namespace).Create(context.Background(), svc, v1.CreateOptions{})
if err != nil {
if k8serrors.IsAlreadyExists(err) {
return fmt.Errorf("MinIO Operator Service %s: already present, skipped", svc.ObjectMeta.Name)
}
return err
}
fmt.Printf("MinIO Operator Service %s: created\n", svc.ObjectMeta.Name)
return nil
}
45 changes: 45 additions & 0 deletions kubectl-minio/cmd/resources/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* This file is part of MinIO Operator
* Copyright (C) 2021, MinIO, Inc.
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

package resources

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// NewServiceForOperator will return a new service for a MinIO Operator webhook server
func NewServiceForOperator(opts OperatorOptions) *corev1.Service {
operatorWebhookHTTPPort := corev1.ServicePort{Port: 4222, Name: "http"}
operatorWebhookHTTPSPort := corev1.ServicePort{Port: 4233, Name: "https"}
return &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Labels: operatorLabels(),
Name: "operator",
Namespace: opts.NS,
},
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
operatorWebhookHTTPPort,
operatorWebhookHTTPSPort,
},
Selector: operatorLabels(),
Type: corev1.ServiceTypeClusterIP,
},
}
}
7 changes: 4 additions & 3 deletions kubectl-minio/cmd/tenant-upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,15 @@ func (u *upgradeCmd) run() error {
u.tenantOpts.Name, u.tenantOpts.Image, t.Spec.Image)
}

// update the image
t.Spec.Image = u.tenantOpts.Image
if u.tenantOpts.ImagePullSecret != "" {
t.Spec.ImagePullSecret = corev1.LocalObjectReference{Name: u.tenantOpts.ImagePullSecret}
}

if !u.output {
return u.upgradeTenant(client, t, t.Spec.Image, u.tenantOpts.Image)
}

// update the image
t.Spec.Image = u.tenantOpts.Image
o, err := yaml.Marshal(&t)
if err != nil {
return err
Expand All @@ -147,6 +146,8 @@ func (u *upgradeCmd) run() error {
func (u *upgradeCmd) upgradeTenant(client *operatorv1.Clientset, t *miniov1.Tenant, c, p string) error {
if helpers.Ask(fmt.Sprintf("Upgrade is a one way process. Are you sure to upgrade Tenant '%s/%s' from version %s to %s?", t.ObjectMeta.Name, t.ObjectMeta.Namespace, c, p)) {
fmt.Printf(color.Bold(fmt.Sprintf("\nUpgrading Tenant '%s/%s'\n\n", t.ObjectMeta.Name, t.ObjectMeta.Namespace)))
// update the image
t.Spec.Image = u.tenantOpts.Image
if _, err := client.MinioV1().Tenants(t.Namespace).Update(context.Background(), t, v1.UpdateOptions{}); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion kubectl-minio/cmd/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func newTenantCmd(out io.Writer, errOut io.Writer) *cobra.Command {
_, err = client.ApiextensionsV1beta1().CustomResourceDefinitions().Get(context.Background(), crdObj.GetObjectMeta().GetName(), v1.GetOptions{})
if err != nil {
if k8serrors.IsNotFound(err) {
return fmt.Errorf("CustomResourceDefinition %s: not found, please run 'kubectl minio operator create' before using tenant command", crdObj.ObjectMeta.Name)
return fmt.Errorf("CustomResourceDefinition %s: not found, please run 'kubectl minio init' before using tenant command", crdObj.ObjectMeta.Name)
}
return err
}
Expand Down