diff --git a/.golangci.yml b/.golangci.yml index bbcec1a0eb7..fe913319d6c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,6 +6,7 @@ linters-settings: locale: US linters: + disable-all: true enable: - typecheck - goimports @@ -16,6 +17,12 @@ linters: - gosimple - deadcode - structcheck + - gomodguard + - gofmt + - unused + - structcheck + - unconvert + - varcheck issues: exclude-use-default: false diff --git a/Makefile b/Makefile index 77b4db5055c..4b1aadd0675 100644 --- a/Makefile +++ b/Makefile @@ -70,7 +70,11 @@ regen-crd-docs: plugin: regen-crd @echo "Building 'kubectl-minio' binary" - @(cd $(PLUGIN_HOME); go build -o kubectl-minio main.go) + @(cd $(PLUGIN_HOME); \ + go vet ./... && \ + go test -race ./... && \ + GO111MODULE=on ${GOPATH}/bin/golangci-lint cache clean && \ + GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=5m --config ../.golangci.yml) .PHONY: logsearchapi logsearchapi: diff --git a/kubectl-minio/cmd/delete.go b/kubectl-minio/cmd/delete.go index 5b1d10ec0c0..6b864a851d2 100644 --- a/kubectl-minio/cmd/delete.go +++ b/kubectl-minio/cmd/delete.go @@ -20,11 +20,9 @@ package cmd import ( "bufio" - "context" "errors" "fmt" "io" - "log" "os" "os/exec" "strings" @@ -33,21 +31,11 @@ import ( "sigs.k8s.io/kustomize/api/types" "sigs.k8s.io/yaml" - "k8s.io/apimachinery/pkg/api/meta" "k8s.io/klog/v2" - rbacv1 "k8s.io/api/rbac/v1" - apiextension "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" - "k8s.io/client-go/dynamic" - "k8s.io/client-go/restmapper" - "github.com/minio/kubectl-minio/cmd/helpers" "github.com/minio/kubectl-minio/cmd/resources" "github.com/spf13/cobra" - - "k8s.io/apimachinery/pkg/runtime" ) const ( @@ -61,7 +49,6 @@ type deleteCmd struct { errOut io.Writer output bool operatorOpts resources.OperatorOptions - steps []runtime.Object } func newDeleteCmd(out io.Writer, errOut io.Writer) *cobra.Command { @@ -73,7 +60,7 @@ func newDeleteCmd(out io.Writer, errOut io.Writer) *cobra.Command { Long: deleteDesc, Example: deleteExample, PreRunE: func(cmd *cobra.Command, args []string) error { - if !helpers.Ask(fmt.Sprintf("Are you sure you want to delete ALL the MinIO Tenants and MinIO Operator?")) { + if !helpers.Ask("Are you sure you want to delete ALL the MinIO Tenants and MinIO Operator?") { return fmt.Errorf(Bold("Aborting Operator deletion\n")) } return nil @@ -118,12 +105,20 @@ func (o *deleteCmd) run(writer io.Writer) error { if o.operatorOpts.Namespace != "" { kustomizationYaml.Namespace = o.operatorOpts.Namespace } + // Compile the kustomization to a file and create on the in memory filesystem - kustYaml, _ := yaml.Marshal(kustomizationYaml) + kustYaml, err := yaml.Marshal(kustomizationYaml) + if err != nil { + return err + } + kustFile, err := inMemSys.Create("kustomization.yaml") + if err != nil { + return err + } + _, err = kustFile.Write(kustYaml) if err != nil { - log.Println(err) return err } @@ -144,8 +139,7 @@ func (o *deleteCmd) run(writer io.Writer) error { if o.output { _, err = writer.Write(yml) - //done - return nil + return err } // do kubectl apply @@ -180,65 +174,3 @@ func (o *deleteCmd) run(writer io.Writer) error { return nil } - -func deleteConsoleResources(opts resources.OperatorOptions, clientset *apiextension.Clientset, dynClient dynamic.Interface, consoleResources []runtime.Object) error { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - groupResources, err := restmapper.GetAPIGroupResources(clientset.Discovery()) - if err != nil { - klog.Info(err) - return errors.New("Cannot get group resources") - } - rm := restmapper.NewDiscoveryRESTMapper(groupResources) - - for _, obj := range consoleResources { - gvk := obj.GetObjectKind().GroupVersionKind() - gk := schema.GroupKind{Group: gvk.Group, Kind: gvk.Kind} - - mapping, err := rm.RESTMapping(gk, gvk.Version) - - // convert the runtime.Object to unstructured.Unstructured - unstructuredObj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj) - if err != nil { - return err - } - var resourceName string - if metaobj, ok := unstructuredObj["metadata"]; ok { - mtobj := metaobj.(map[string]interface{}) - if name, ok2 := mtobj["name"]; ok2 { - resourceName = name.(string) - } - } - - switch obj.(type) { - case *rbacv1.ClusterRoleBinding: - if err := clusterScopeDelete(dynClient, mapping, ctx, resourceName); err != nil { - return err - } - case *rbacv1.ClusterRole: - if err := clusterScopeDelete(dynClient, mapping, ctx, resourceName); err != nil { - return err - } - default: - if err := namespaceScopeDelete(opts, dynClient, mapping, ctx, resourceName); err != nil { - return err - } - } - } - return nil -} - -func clusterScopeDelete(dynClient dynamic.Interface, mapping *meta.RESTMapping, ctx context.Context, name string) error { - if err := dynClient.Resource(mapping.Resource).Delete(ctx, name, metav1.DeleteOptions{}); err != nil { - return err - } - return nil -} - -func namespaceScopeDelete(opts resources.OperatorOptions, dynClient dynamic.Interface, mapping *meta.RESTMapping, ctx context.Context, name string) error { - if err := dynClient.Resource(mapping.Resource).Namespace(opts.Namespace).Delete(ctx, name, metav1.DeleteOptions{}); err != nil { - return err - } - return nil -} diff --git a/kubectl-minio/cmd/helpers/helpers.go b/kubectl-minio/cmd/helpers/helpers.go index 186f7599c76..4bddaf3dfc2 100644 --- a/kubectl-minio/cmd/helpers/helpers.go +++ b/kubectl-minio/cmd/helpers/helpers.go @@ -95,8 +95,7 @@ func GetKubeDynamicClient() (dynamic.Interface, error) { return nil, err } - dynClient, err := dynamic.NewForConfig(config) - return dynClient, nil + return dynamic.NewForConfig(config) } // GetKubeOperatorClient provides k8s client for operator diff --git a/kubectl-minio/cmd/init.go b/kubectl-minio/cmd/init.go index 4873b7b2a8b..e8b225889ee 100644 --- a/kubectl-minio/cmd/init.go +++ b/kubectl-minio/cmd/init.go @@ -24,7 +24,6 @@ import ( "errors" "fmt" "io" - "log" "os" "os/exec" "strings" @@ -41,10 +40,8 @@ import ( "github.com/minio/kubectl-minio/cmd/helpers" "github.com/minio/kubectl-minio/cmd/resources" - rsc "github.com/minio/operator/resources" "github.com/spf13/cobra" - "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/kustomize/api/krusty" ) @@ -59,7 +56,6 @@ type operatorInitCmd struct { errOut io.Writer output bool operatorOpts resources.OperatorOptions - steps []runtime.Object } func newInitCmd(out io.Writer, errOut io.Writer) *cobra.Command { @@ -99,19 +95,13 @@ func newInitCmd(out io.Writer, errOut io.Writer) *cobra.Command { return cmd } -var resourcesFS = rsc.GetStaticResources() - -type OpInt struct { - Op string `json:"op"` - Path string `json:"path"` - Value int `json:"value"` -} -type OpStr struct { +type opStr struct { Op string `json:"op"` Path string `json:"path"` Value string `json:"value"` } -type OpInterface struct { + +type opInterface struct { Op string `json:"op"` Path string `json:"path"` Value interface{} `json:"value"` @@ -140,21 +130,21 @@ func (o *operatorInitCmd) run(writer io.Writer) error { var operatorDepPatches []interface{} // create patches for the supplied arguments if o.operatorOpts.Image != "" { - operatorDepPatches = append(operatorDepPatches, OpStr{ + operatorDepPatches = append(operatorDepPatches, opStr{ Op: "replace", Path: "/spec/template/spec/containers/0/image", Value: o.operatorOpts.Image, }) } // create an empty array - operatorDepPatches = append(operatorDepPatches, OpInterface{ + operatorDepPatches = append(operatorDepPatches, opInterface{ Op: "add", Path: "/spec/template/spec/containers/0/env", Value: []interface{}{}, }) if o.operatorOpts.ClusterDomain != "" { - operatorDepPatches = append(operatorDepPatches, OpInterface{ + operatorDepPatches = append(operatorDepPatches, opInterface{ Op: "add", Path: "/spec/template/spec/containers/0/env/0", Value: corev1.EnvVar{ @@ -164,7 +154,7 @@ func (o *operatorInitCmd) run(writer io.Writer) error { }) } if o.operatorOpts.NSToWatch != "" { - operatorDepPatches = append(operatorDepPatches, OpInterface{ + operatorDepPatches = append(operatorDepPatches, opInterface{ Op: "add", Path: "/spec/template/spec/containers/0/env/0", Value: corev1.EnvVar{ @@ -174,7 +164,7 @@ func (o *operatorInitCmd) run(writer io.Writer) error { }) } if o.operatorOpts.TenantMinIOImage != "" { - operatorDepPatches = append(operatorDepPatches, OpInterface{ + operatorDepPatches = append(operatorDepPatches, opInterface{ Op: "add", Path: "/spec/template/spec/containers/0/env/0", Value: corev1.EnvVar{ @@ -184,7 +174,7 @@ func (o *operatorInitCmd) run(writer io.Writer) error { }) } if o.operatorOpts.TenantConsoleImage != "" { - operatorDepPatches = append(operatorDepPatches, OpInterface{ + operatorDepPatches = append(operatorDepPatches, opInterface{ Op: "add", Path: "/spec/template/spec/containers/0/env/0", Value: corev1.EnvVar{ @@ -194,7 +184,7 @@ func (o *operatorInitCmd) run(writer io.Writer) error { }) } if o.operatorOpts.TenantKesImage != "" { - operatorDepPatches = append(operatorDepPatches, OpInterface{ + operatorDepPatches = append(operatorDepPatches, opInterface{ Op: "add", Path: "/spec/template/spec/containers/0/env/0", Value: corev1.EnvVar{ @@ -204,7 +194,7 @@ func (o *operatorInitCmd) run(writer io.Writer) error { }) } if o.operatorOpts.ImagePullSecret != "" { - operatorDepPatches = append(operatorDepPatches, OpInterface{ + operatorDepPatches = append(operatorDepPatches, opInterface{ Op: "add", Path: "/spec/template/spec/imagePullSecrets", Value: []corev1.LocalObjectReference{{Name: o.operatorOpts.ImagePullSecret}}, @@ -213,7 +203,7 @@ func (o *operatorInitCmd) run(writer io.Writer) error { // attach the patches to the kustomization file if len(operatorDepPatches) > 0 { kustomizationYaml.PatchesJson6902 = append(kustomizationYaml.PatchesJson6902, types.Patch{ - Patch: o.serializeJsonPachOps(operatorDepPatches), + Patch: o.serializeJSONPachOps(operatorDepPatches), Target: &types.Selector{ Gvk: resid.Gvk{ Group: "apps", @@ -228,8 +218,8 @@ func (o *operatorInitCmd) run(writer io.Writer) error { if o.operatorOpts.ConsoleImage != "" { kustomizationYaml.PatchesJson6902 = append(kustomizationYaml.PatchesJson6902, types.Patch{ - Patch: o.serializeJsonPachOps([]interface{}{ - OpStr{ + Patch: o.serializeJSONPachOps([]interface{}{ + opStr{ Op: "replace", Path: "/spec/template/spec/containers/0/image", Value: o.operatorOpts.ConsoleImage, @@ -250,11 +240,18 @@ func (o *operatorInitCmd) run(writer io.Writer) error { kustomizationYaml.Namespace = o.operatorOpts.Namespace } // Compile the kustomization to a file and create on the in memory filesystem - kustYaml, _ := yaml.Marshal(kustomizationYaml) + kustYaml, err := yaml.Marshal(kustomizationYaml) + if err != nil { + return err + } + kustFile, err := inMemSys.Create("kustomization.yaml") + if err != nil { + return err + } + _, err = kustFile.Write(kustYaml) if err != nil { - log.Println(err) return err } @@ -275,8 +272,7 @@ func (o *operatorInitCmd) run(writer io.Writer) error { if o.output { _, err = writer.Write(yml) - //done - return nil + return err } // do kubectl apply @@ -326,7 +322,7 @@ func (o *operatorInitCmd) run(writer io.Writer) error { return nil } -func (o *operatorInitCmd) serializeJsonPachOps(jp []interface{}) string { - jpJson, _ := json.Marshal(jp) - return string(jpJson) +func (o *operatorInitCmd) serializeJSONPachOps(jp []interface{}) string { + jpJSON, _ := json.Marshal(jp) + return string(jpJSON) } diff --git a/kubectl-minio/cmd/kubectl-minio.go b/kubectl-minio/cmd/kubectl-minio.go index 2acd125b921..30e03e4b3cc 100644 --- a/kubectl-minio/cmd/kubectl-minio.go +++ b/kubectl-minio/cmd/kubectl-minio.go @@ -23,7 +23,6 @@ import ( "github.com/spf13/cobra" "k8s.io/cli-runtime/pkg/genericclioptions" - "k8s.io/client-go/kubernetes" // Workaround for auth import issues refer https://github.com/minio/operator/issues/283 _ "k8s.io/client-go/plugin/pkg/client/auth" @@ -32,12 +31,6 @@ import ( "github.com/minio/kubectl-minio/cmd/helpers" ) -var ( - kubeConfig string - namespace string - kubeClient *kubernetes.Clientset -) - const ( minioDesc = `Deploy and manage the multi tenant, S3 API compatible object storage on Kubernetes` kubeconfig = "kubeconfig" diff --git a/kubectl-minio/cmd/proxy.go b/kubectl-minio/cmd/proxy.go index 12da6b62282..e3910c40ddb 100644 --- a/kubectl-minio/cmd/proxy.go +++ b/kubectl-minio/cmd/proxy.go @@ -35,8 +35,6 @@ import ( "github.com/minio/kubectl-minio/cmd/helpers" "github.com/minio/kubectl-minio/cmd/resources" "github.com/spf13/cobra" - - "k8s.io/apimachinery/pkg/runtime" ) const ( @@ -48,9 +46,7 @@ const ( type operatorProxyCmd struct { out io.Writer errOut io.Writer - output bool operatorOpts resources.OperatorOptions - steps []runtime.Object } func newProxyCmd(out io.Writer, errOut io.Writer) *cobra.Command { diff --git a/kubectl-minio/cmd/resources/common.go b/kubectl-minio/cmd/resources/common.go index 1eb7dd53604..055e515a977 100644 --- a/kubectl-minio/cmd/resources/common.go +++ b/kubectl-minio/cmd/resources/common.go @@ -115,6 +115,7 @@ func GetSchemeDecoder() func(data []byte, defaults *schema.GroupVersionKind, int return decode } +// LoadTenantCRD loads tenant crds as k8s runtime object. func LoadTenantCRD(decode func(data []byte, defaults *schema.GroupVersionKind, into runtime.Object) (runtime.Object, *schema.GroupVersionKind, error)) *apiextensionv1.CustomResourceDefinition { contents, err := resourcesFS.Open("base/crds/minio.min.io_tenants.yaml") if err != nil { @@ -138,6 +139,7 @@ func LoadTenantCRD(decode func(data []byte, defaults *schema.GroupVersionKind, i return crdObj } +// GetResourceFileSys file func GetResourceFileSys() (filesys.FileSystem, error) { inMemSys := filesys.MakeFsInMemory() // copy from the resources into the target folder on the in memory FS @@ -169,12 +171,12 @@ func copyFileToMemFS(src, dst string, memFS filesys.FileSystem) error { // Note: I had to read the whole string, for some reason io.Copy was not copying the whole content input, err := ioutil.ReadAll(srcFileDesc) - _, err = dstFileDesc.Write(input) if err != nil { return err } - return nil + _, err = dstFileDesc.Write(input) + return err } func copyDirtoMemFS(src string, dst string, memFS filesys.FileSystem) error { diff --git a/kubectl-minio/cmd/tenant-create.go b/kubectl-minio/cmd/tenant-create.go index 72eff7c349e..588c78df2f1 100644 --- a/kubectl-minio/cmd/tenant-create.go +++ b/kubectl-minio/cmd/tenant-create.go @@ -43,9 +43,8 @@ import ( const ( createDesc = ` 'create' command creates a new MinIO tenant` - createExample = ` kubectl minio tenant create tenant1 --servers 4 --volumes 16 --capacity 16Ti --namespace tenant1-ns` - tenantSecretSuffix = "-creds-secret" - consoleSecretSuffix = "-console-secret" + createExample = ` kubectl minio tenant create tenant1 --servers 4 --volumes 16 --capacity 16Ti --namespace tenant1-ns` + tenantSecretSuffix = "-creds-secret" ) type createCmd struct { @@ -158,7 +157,7 @@ func (c *createCmd) run(args []string) error { func createTenant(oclient *operatorv1.Clientset, kclient *kubernetes.Clientset, t *miniov2.Tenant, s, console *corev1.Secret) error { if _, err := kclient.CoreV1().Namespaces().Get(context.Background(), t.Namespace, metav1.GetOptions{}); err != nil { - return errors.New(fmt.Sprintf("Namespace %s not found, please create the namespace using 'kubectl create ns %s'", t.Namespace, t.Namespace)) + return fmt.Errorf("Namespace %s not found, please create the namespace using 'kubectl create ns %s'", t.Namespace, t.Namespace) } if _, err := kclient.CoreV1().Secrets(t.Namespace).Create(context.Background(), s, metav1.CreateOptions{}); err != nil { return err diff --git a/kubectl-minio/cmd/tenant-delete.go b/kubectl-minio/cmd/tenant-delete.go index 6173eb094a6..88be3dd85f3 100644 --- a/kubectl-minio/cmd/tenant-delete.go +++ b/kubectl-minio/cmd/tenant-delete.go @@ -34,12 +34,6 @@ import ( "github.com/spf13/cobra" ) -const ( - tenantDeleteDesc = ` -'delete' command deletes a MinIO tenant` - tenantDeleteExample = ` kubectl minio tenant delete tenant1 --namespace tenant1-ns` -) - type tenantDeleteCmd struct { out io.Writer errOut io.Writer diff --git a/kubectl-minio/cmd/tenant-info.go b/kubectl-minio/cmd/tenant-info.go index f60cb61638f..fc63f2744a4 100644 --- a/kubectl-minio/cmd/tenant-info.go +++ b/kubectl-minio/cmd/tenant-info.go @@ -36,9 +36,7 @@ import ( ) const ( - infoDesc = ` -'info' command lists pools from a MinIO tenant` - infoExample = ` kubectl minio tenant info tenant1 --namespace tenant1-ns` + infoDesc = `'info' command lists pools from a MinIO tenant` ) type infoCmd struct { diff --git a/kubectl-minio/cmd/tenant-list.go b/kubectl-minio/cmd/tenant-list.go index 99c4ceb876b..8124612de3b 100644 --- a/kubectl-minio/cmd/tenant-list.go +++ b/kubectl-minio/cmd/tenant-list.go @@ -33,9 +33,7 @@ import ( ) const ( - listDesc = ` - 'list' command lists all MinIO tenant managed by the Operator` - listExample = ` kubectl minio tenant list ` + listDesc = `'list' command lists all MinIO tenant managed by the Operator` ) type listCmd struct { diff --git a/kubectl-minio/cmd/tenant-upgrade.go b/kubectl-minio/cmd/tenant-upgrade.go index 97225351b57..c251c567dc8 100644 --- a/kubectl-minio/cmd/tenant-upgrade.go +++ b/kubectl-minio/cmd/tenant-upgrade.go @@ -37,9 +37,7 @@ import ( ) const ( - upgradeDesc = ` -'upgrade' command upgrades a MinIO tenant to the specified MinIO version` - upgradeExample = ` kubectl minio tenant upgrade tenant1 --image minio/minio:RELEASE.2021-09-03T03-56-13Z --namespace tenant1-ns` + upgradeDesc = `'upgrade' command upgrades a MinIO tenant to the specified MinIO version` ) type upgradeCmd struct { @@ -158,7 +156,7 @@ func (u *upgradeCmd) upgradeTenant(client *operatorv1.Clientset, t *miniov2.Tena return err } } else { - fmt.Printf(Bold(fmt.Sprintf("\nAborting Tenant upgrade\n\n"))) + fmt.Printf(Bold("\nAborting Tenant upgrade\n\n")) } return nil } diff --git a/kubectl-minio/cmd/version.go b/kubectl-minio/cmd/version.go index 0276b04692f..925018c10c5 100644 --- a/kubectl-minio/cmd/version.go +++ b/kubectl-minio/cmd/version.go @@ -41,7 +41,6 @@ const ( type operatorVersionCmd struct { out io.Writer errOut io.Writer - output bool } func newVersionCmd(out io.Writer, errOut io.Writer) *cobra.Command { diff --git a/pkg/controller/cluster/main-controller.go b/pkg/controller/cluster/main-controller.go index b50816f45db..ca958df777d 100644 --- a/pkg/controller/cluster/main-controller.go +++ b/pkg/controller/cluster/main-controller.go @@ -346,16 +346,16 @@ func (c *Controller) Start(threadiness int, stopCh <-chan struct{}) error { close(apiWillStart) // use those certificates to configure the web server if err := c.ws.ListenAndServeTLS(publicCertPath, publicKeyPath); err != http.ErrServerClosed { - klog.Infof("HTTPS server ListenAndServeTLS: %v", err) - return + klog.Infof("HTTPS server ListenAndServeTLS failed: %v", err) + panic(err) } } else { klog.Infof("Starting HTTP api server") close(apiWillStart) // start server without TLS if err := c.ws.ListenAndServe(); err != http.ErrServerClosed { - klog.Infof("HTTP server ListenAndServe: %v", err) - return + klog.Infof("HTTP server ListenAndServe failed: %v", err) + panic(err) } } }() diff --git a/pkg/controller/cluster/operator.go b/pkg/controller/cluster/operator.go index 9492b925b16..2b7d106dae8 100644 --- a/pkg/controller/cluster/operator.go +++ b/pkg/controller/cluster/operator.go @@ -19,6 +19,7 @@ package cluster import ( "context" "crypto/rand" + "crypto/tls" "crypto/x509" "crypto/x509/pkix" "encoding/pem" @@ -82,7 +83,7 @@ func (c *Controller) generateTLSCert() (string, string) { operatorTLSCert, err := c.kubeClientSet.CoreV1().Secrets(namespace).Get(ctx, OperatorTLSSecretName, metav1.GetOptions{}) if err != nil { if k8serrors.IsNotFound(err) { - klog.Infof("operator TLS secret not found", err.Error()) + klog.Infof("operator TLS secret not found %v", err) if err = c.checkAndCreateOperatorCSR(ctx, operatorDeployment); err != nil { klog.Infof("Waiting for the operator certificates to be issued %v", err.Error()) time.Sleep(time.Second * 10) @@ -99,7 +100,7 @@ func (c *Controller) generateTLSCert() (string, string) { panic(err) } } else { - panic(errors.New("operator TLS wrong format")) + panic(errors.New("operator TLS 'public.crt' missing")) } if val, ok := operatorTLSCert.Data["private.key"]; ok { @@ -108,12 +109,17 @@ func (c *Controller) generateTLSCert() (string, string) { panic(err) } } else { - panic(errors.New("operator TLS wrong format")) + panic(errors.New("operator TLS 'private.key' missing")) } break } } + // validate certificates if they are valid, if not panic right here. + if _, err = tls.LoadX509KeyPair(publicCertPath, publicKeyPath); err != nil { + panic(err) + } + return publicCertPath, publicKeyPath } diff --git a/pkg/controller/cluster/webhook.go b/pkg/controller/cluster/webhook.go index df764ae409c..83c5bf96391 100644 --- a/pkg/controller/cluster/webhook.go +++ b/pkg/controller/cluster/webhook.go @@ -53,29 +53,28 @@ func configureWebhookServer(c *Controller) *http.Server { Path(miniov2.WebhookAPIGetenv + "/{namespace}/{name:.+}"). HandlerFunc(c.GetenvHandler). Queries(restQueries("key")...) + router.Methods(http.MethodPost). Path(miniov2.WebhookAPIBucketService + "/{namespace}/{name:.+}"). HandlerFunc(c.BucketSrvHandler). Queries(restQueries("bucket")...) + router.Methods(http.MethodGet). PathPrefix(miniov2.WebhookAPIUpdate). Handler(http.StripPrefix(miniov2.WebhookAPIUpdate, http.FileServer(http.Dir(updatePath)))) + // CRD Conversion router.Methods(http.MethodPost). Path(miniov2.WebhookCRDConversaion). HandlerFunc(c.CRDConversionHandler) - //. - // Queries(restQueries("bucket")...) - router.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Println(r) - }) + router.NotFoundHandler = http.NotFoundHandler() s := &http.Server{ Addr: ":" + miniov2.WebhookDefaultPort, Handler: router, - ReadTimeout: 10 * time.Second, - WriteTimeout: 10 * time.Second, + ReadTimeout: time.Minute, + WriteTimeout: time.Minute, MaxHeaderBytes: 1 << 20, }