Skip to content

Commit

Permalink
Add update command + config parameters for operatorui and operatorapi
Browse files Browse the repository at this point in the history
Signed-off-by: dviejokfs <dviejo@kungfusoftware.es>
  • Loading branch information
dviejokfs committed Aug 4, 2022
1 parent 32a9470 commit 8142de5
Show file tree
Hide file tree
Showing 13 changed files with 314 additions and 16 deletions.
6 changes: 6 additions & 0 deletions charts/hlf-operator-api/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ spec:
- "{{.Values.hlf.mspID}}"
- "--user"
- "{{.Values.hlf.user}}"
{{ end }}
{{ if and .Values.auth.oidcJWKS .Values.auth.oidcIssuer }}
- "--auth-issuer"
- "{{ .Values.auth.oidcIssuer }}"
- "--auth-jwks"
- "{{ .Values.auth.oidcJWKS }}"
{{ end }}
livenessProbe:
httpGet:
Expand Down
3 changes: 3 additions & 0 deletions charts/hlf-operator-api/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ image:
tag: ""


auth:
oidcJWKS: ""
oidcIssuer: ""

hlf:
mspID: ""
Expand Down
4 changes: 2 additions & 2 deletions charts/hlf-operator-ui/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ image:

logoUrl: ""
auth:
oidcAuthority: "",
oidcClientId: "",
oidcAuthority: ""
oidcClientId: ""
oidcScope: ""

imagePullSecrets: []
Expand Down
10 changes: 3 additions & 7 deletions controllers/operatorui/operatorui.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type Status struct {
NodePort int
}

func GetConsoleState(conf *action.Configuration, config *rest.Config, releaseName string, ns string) (*hlfv1alpha1.FabricOperatorUIStatus, error) {
func GetOperatorUIState(conf *action.Configuration, config *rest.Config, releaseName string, ns string) (*hlfv1alpha1.FabricOperatorUIStatus, error) {
ctx := context.Background()
cmd := action.NewGet(conf)
rel, err := cmd.Run(releaseName)
Expand Down Expand Up @@ -272,7 +272,7 @@ func (r *FabricOperatorUIReconciler) Reconcile(req ctrl.Request) (ctrl.Result, e
r.setConditionStatus(ctx, fabricOpConsole, hlfv1alpha1.FailedStatus, false, err, false)
return r.updateCRStatusOrFailReconcile(ctx, r.Log, fabricOpConsole)
}
s, err := GetConsoleState(cfg, r.Config, releaseName, ns)
s, err := GetOperatorUIState(cfg, r.Config, releaseName, ns)
if err != nil {
r.setConditionStatus(ctx, fabricOpConsole, hlfv1alpha1.FailedStatus, false, err, false)
return r.updateCRStatusOrFailReconcile(ctx, r.Log, fabricOpConsole)
Expand Down Expand Up @@ -480,11 +480,7 @@ func GetConfig(conf *hlfv1alpha1.FabricOperatorUI) (*HLFOperatorUIChart, error)
Hosts: hosts,
}
}
auth := Auth{
OIDCAuthority: spec.Auth.OIDCAuthority,
OIDCClientId: spec.Auth.OIDCClientId,
OIDCScope: spec.Auth.OIDCScope,
}
auth := Auth{}
if spec.Auth != nil {
auth.OIDCAuthority = spec.Auth.OIDCAuthority
auth.OIDCClientId = spec.Auth.OIDCClientId
Expand Down
2 changes: 1 addition & 1 deletion controllers/operatorui/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ type HLFOperatorUIChart struct {
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
Affinity *corev1.Affinity `json:"affinity"`
LogoURL string `json:"logoUrl"`
Auth Auth `json:"auth"`
Auth Auth `json:"auth,omitempty"`
}

type Auth struct {
Expand Down
4 changes: 2 additions & 2 deletions kubectl-hlf/cmd/helpers/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ const (
DefaultOperationsConsoleVersion = "latest"

DefaultOperationsOperatorUIImage = "ghcr.io/kfsoftware/hlf-operator-ui"
DefaultOperationsOperatorUIVersion = "0.0.7"
DefaultOperationsOperatorUIVersion = "0.0.10"

DefaultOperationsOperatorAPIImage = "ghcr.io/kfsoftware/hlf-operator-api"
DefaultOperationsOperatorAPIVersion = "v0.0.7"
DefaultOperationsOperatorAPIVersion = "v0.0.10"

DefaultFSServerImage = "quay.io/kfsoftware/fs-peer"
DefaultFSServerVersion = "amd64-2.2.0-0.0.1"
Expand Down
19 changes: 16 additions & 3 deletions kubectl-hlf/cmd/operatorapi/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ type Options struct {
MSPID string
User string
HLFKey string
OIDCIssuer string
OIDCJWKS string
Replicas int
}

func (o Options) Validate() error {
if o.Replicas < 1 {
return fmt.Errorf("replicas must be greater than 0")
}
return nil
}

Expand Down Expand Up @@ -88,9 +94,13 @@ func (c *createCmd) run() error {
Image: c.apiOpts.Image,
Tag: c.apiOpts.Version,
ImagePullPolicy: "Always",
Istio: v1alpha1.FabricIstio{},
Ingress: ingress,
Replicas: 1,
Auth: &v1alpha1.FabricOperatorAPIAuth{
OIDCJWKS: c.apiOpts.OIDCJWKS,
OIDCIssuer: c.apiOpts.OIDCIssuer,
},
Istio: v1alpha1.FabricIstio{},
Ingress: ingress,
Replicas: c.apiOpts.Replicas,
HLFConfig: v1alpha1.FabricOperatorAPIHLFConfig{
MSPID: c.apiOpts.MSPID,
User: c.apiOpts.User,
Expand Down Expand Up @@ -153,6 +163,9 @@ func newCreateOperatorAPICmd(out io.Writer, errOut io.Writer) *cobra.Command {
f.StringVarP(&c.apiOpts.User, "hlf-user", "", "", "HLF Network Config User")
f.StringVarP(&c.apiOpts.HLFSecretName, "hlf-secret", "", "", "HLF Network Config Secret name")
f.StringVarP(&c.apiOpts.HLFKey, "hlf-secret-key", "", "", "HLF Network Config Secret key")
f.StringVarP(&c.apiOpts.OIDCJWKS, "oidc-jwks", "", "", "OIDC JWKS URL")
f.StringVarP(&c.apiOpts.OIDCIssuer, "oidc-issuer", "", "", "OIDC Issuer URL")
f.IntVarP(&c.apiOpts.Replicas, "replicas", "", 1, "Number of replicas of the Operator UI")
f.StringArrayVarP(&c.apiOpts.Hosts, "hosts", "", []string{}, "External hosts")
f.BoolVarP(&c.apiOpts.Output, "output", "o", false, "Output in yaml")
return cmd
Expand Down
1 change: 1 addition & 0 deletions kubectl-hlf/cmd/operatorapi/operatorapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func NewOperatorAPICMD(out io.Writer, errOut io.Writer) *cobra.Command {
cmd.AddCommand(
newCreateOperatorAPICmd(out, errOut),
newDeleteOperatorAPICmd(out, errOut),
newUpdateOperatorAPICmd(out, errOut),
)

return cmd
Expand Down
131 changes: 131 additions & 0 deletions kubectl-hlf/cmd/operatorapi/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package operatorapi

import (
"context"
"fmt"
"github.com/kfsoftware/hlf-operator/api/hlf.kungfusoftware.es/v1alpha1"
"github.com/kfsoftware/hlf-operator/kubectl-hlf/cmd/helpers"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"io"
"k8s.io/api/networking/v1beta1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type updateCmd struct {
out io.Writer
errOut io.Writer
apiOpts Options
}

func (c *updateCmd) validate() error {
return c.apiOpts.Validate()
}
func (c *updateCmd) run() error {
oclient, err := helpers.GetKubeOperatorClient()
if err != nil {
return err
}
hosts := []v1alpha1.IngressHost{}
for _, host := range c.apiOpts.Hosts {
hosts = append(hosts, v1alpha1.IngressHost{
Paths: []v1alpha1.IngressPath{
{
Path: "/",
PathType: "Prefix",
},
},
Host: host,
})
}
ingress := v1alpha1.Ingress{
Enabled: true,
ClassName: "",
Annotations: map[string]string{
"kubernetes.io/ingress.class": c.apiOpts.IngressClassName,
},
TLS: []v1beta1.IngressTLS{},
Hosts: hosts,
}
if c.apiOpts.TLSSecretName != "" {
ingress.TLS = []v1beta1.IngressTLS{
{
Hosts: c.apiOpts.Hosts,
SecretName: c.apiOpts.TLSSecretName,
},
}
}
config := v1alpha1.FabricOperatorAPIHLFConfig{
MSPID: c.apiOpts.MSPID,
User: c.apiOpts.User,
NetworkConfig: v1alpha1.FabricOperatorAPINetworkConfig{
SecretName: c.apiOpts.HLFSecretName,
Key: c.apiOpts.HLFKey,
},
}
auth := &v1alpha1.FabricOperatorAPIAuth{
OIDCJWKS: c.apiOpts.OIDCJWKS,
OIDCIssuer: c.apiOpts.OIDCIssuer,
}
ctx := context.Background()
fabricAPI, err := oclient.HlfV1alpha1().FabricOperatorAPIs(c.apiOpts.NS).Get(ctx, c.apiOpts.Name, v1.GetOptions{})
if err != nil {
return errors.Wrapf(err, "failed to get Fabric Operator UI %s", c.apiOpts.Name)
}
fabricAPI.Spec.Ingress = ingress
fabricAPI.Spec.Image = c.apiOpts.Image
fabricAPI.Spec.Tag = c.apiOpts.Version
fabricAPI.Spec.HLFConfig = config
fabricAPI.Spec.Auth = auth
fabricAPI.Spec.Replicas = c.apiOpts.Replicas
if c.apiOpts.Output {
ot, err := helpers.MarshallWithoutStatus(&fabricAPI)
if err != nil {
return err
}
fmt.Println(string(ot))
} else {
ctx := context.Background()
_, err = oclient.HlfV1alpha1().FabricOperatorAPIs(c.apiOpts.NS).Update(
ctx,
fabricAPI,
v1.UpdateOptions{},
)
if err != nil {
return err
}
log.Infof("Operator API %s created on namespace %s", fabricAPI.Name, fabricAPI.Namespace)
}
return nil
}
func newUpdateOperatorAPICmd(out io.Writer, errOut io.Writer) *cobra.Command {
c := updateCmd{out: out, errOut: errOut}
cmd := &cobra.Command{
Use: "update",
Short: "Update a Operator API",
RunE: func(cmd *cobra.Command, args []string) error {
if err := c.validate(); err != nil {
return err
}
return c.run()
},
}
f := cmd.Flags()
f.StringVar(&c.apiOpts.Name, "name", "", "Name of the Operator API to update")
f.StringVarP(&c.apiOpts.NS, "namespace", "n", helpers.DefaultNamespace, "Namespace scope for this request")
f.StringVarP(&c.apiOpts.Image, "image", "", helpers.DefaultOperationsOperatorAPIImage, "Image of the Operator API")
f.StringVarP(&c.apiOpts.Version, "version", "", helpers.DefaultOperationsOperatorAPIVersion, "Version of the Operator API")
f.StringVarP(&c.apiOpts.TLSSecretName, "tls-secret-name", "", "", "TLS Secret for the Operator API")
f.StringVarP(&c.apiOpts.IngressClassName, "ingress-class-name", "", "istio", "Ingress class name")
f.StringVarP(&c.apiOpts.MSPID, "hlf-mspid", "", "", "HLF Network Config MSPID")
f.StringVarP(&c.apiOpts.User, "hlf-user", "", "", "HLF Network Config User")
f.IntVarP(&c.apiOpts.Replicas, "replicas", "", 1, "Number of replicas of the Operator UI")
f.StringVarP(&c.apiOpts.HLFSecretName, "hlf-secret", "", "", "HLF Network Config Secret name")
f.StringVarP(&c.apiOpts.HLFKey, "hlf-secret-key", "", "", "HLF Network Config Secret key")
f.StringVarP(&c.apiOpts.OIDCJWKS, "oidc-jwks", "", "", "OIDC JWKS URL")
f.StringVarP(&c.apiOpts.OIDCIssuer, "oidc-issuer", "", "", "OIDC Issuer URL")
f.StringArrayVarP(&c.apiOpts.Hosts, "hosts", "", []string{}, "External hosts")
f.BoolVarP(&c.apiOpts.Output, "output", "o", false, "Output in yaml")
return cmd
}
21 changes: 20 additions & 1 deletion kubectl-hlf/cmd/operatorui/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,20 @@ type Options struct {
TLSSecretName string
APIURL string
IngresClassName string
LogoURL string
OIDCAuthority string
OIDCClientId string
OIDCScope string
Replicas int
}

func (o Options) Validate() error {
if o.APIURL == "" {
return fmt.Errorf("--api-url is required")
}
if o.Replicas < 1 {
return fmt.Errorf("--replicas must be greater than 0")
}
return nil
}

Expand Down Expand Up @@ -89,12 +97,18 @@ func (c *createCmd) run() error {
Limits: nil,
Requests: nil,
},
LogoURL: c.uiOpts.LogoURL,
Auth: &v1alpha1.FabricOperatorUIAuth{
OIDCAuthority: c.uiOpts.OIDCAuthority,
OIDCClientId: c.uiOpts.OIDCClientId,
OIDCScope: c.uiOpts.OIDCScope,
},
APIURL: c.uiOpts.APIURL,
Image: c.uiOpts.Image,
Tag: c.uiOpts.Version,
ImagePullPolicy: "Always",
Tolerations: []corev1.Toleration{},
Replicas: 1,
Replicas: c.uiOpts.Replicas,
Env: []corev1.EnvVar{},
ImagePullSecrets: []corev1.LocalObjectReference{},
Affinity: &corev1.Affinity{},
Expand Down Expand Up @@ -144,5 +158,10 @@ func newCreateOperatorUICmd(out io.Writer, errOut io.Writer) *cobra.Command {
f.StringVarP(&c.uiOpts.APIURL, "api-url", "", "", "API URL for the Operator UI")
f.StringArrayVarP(&c.uiOpts.Hosts, "hosts", "", []string{}, "External hosts")
f.BoolVarP(&c.uiOpts.Output, "output", "o", false, "Output in yaml")
f.IntVarP(&c.uiOpts.Replicas, "replicas", "", 1, "Number of replicas of the Operator UI")
f.StringVarP(&c.uiOpts.LogoURL, "logo-url", "", "", "Logo URL for the Operator UI")
f.StringVarP(&c.uiOpts.OIDCAuthority, "oidc-authority", "", "", "OIDC Authority for the Operator UI")
f.StringVarP(&c.uiOpts.OIDCClientId, "oidc-client-id", "", "", "OIDC Client ID for the Operator UI")
f.StringVarP(&c.uiOpts.OIDCScope, "oidc-scope", "", "", "OIDC Scope for the Operator UI")
return cmd
}
1 change: 1 addition & 0 deletions kubectl-hlf/cmd/operatorui/operatorui.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func NewOperatorUICMD(out io.Writer, errOut io.Writer) *cobra.Command {
cmd.AddCommand(
newCreateOperatorUICmd(out, errOut),
newDeleteOperatorUICmd(out, errOut),
newUpdateOperatorUICmd(out, errOut),
)

return cmd
Expand Down
Loading

0 comments on commit 8142de5

Please sign in to comment.