Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

Add IstioConfig under Workload Details #1901

Merged
merged 5 commits into from Sep 2, 2020

Conversation

lucasponce
Copy link
Contributor

@lucasponce lucasponce commented Aug 28, 2020

Related to kiali/kiali#3015

Requires kiali/kiali#3157

It adds IstioConfig linked with a workload (resources with some workloadSelector that matches the workload labels).

image

For testers, I've used this (somehow artificial) example (you can modify it inside Kiali to check that validations are working):

apiVersion: security.istio.io/v1beta1
kind: PeerAuthentication
metadata:
  name: details-pa
  namespace: default
spec:
  selector:
    matchLabels:
      app: details
  mtls:
    mode: PERMISSIVE
---
apiVersion: security.istio.io/v1beta1
kind: RequestAuthentication
metadata:
  name: details-ra
  namespace: default
spec:
  selector:
    matchLabels:
      app: details
  jwtRules:
    - issuer: "issuer-foo"
      jwksUri: https://example.com/.well-known/jwks.json
---
apiVersion: security.istio.io/v1beta1
kind: AuthorizationPolicy
metadata:
  name: details-ap
  namespace: default
spec:
  selector:
    matchLabels:
      app: details
  rules:
    - from:
        - source:
            requestPrincipals: ["*"]
---
apiVersion: networking.istio.io/v1alpha3
kind: Sidecar
metadata:
  name: details-sc
  namespace: default
spec:
  workloadSelector:
    labels:
      app: details
  ingress:
    - port:
        number: 9080
        protocol: HTTP
        name: somename
      defaultEndpoint: unix:///var/run/someuds.sock
  egress:
    - port:
        number: 9080
        protocol: HTTP
        name: egresshttp
      hosts:
        - "prod-us1/*"
    - hosts:
        - "istio-system/*"
---
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
  name: details-ef
  namespace: default
spec:
  workloadSelector:
    labels:
      app: details
  configPatches:
    # The first patch adds the lua filter to the listener/http connection manager
    - applyTo: HTTP_FILTER
      match:
        context: SIDECAR_INBOUND
        listener:
          portNumber: 8080
          filterChain:
            filter:
              name: "envoy.http_connection_manager"
              subFilter:
                name: "envoy.router"
      patch:
        operation: INSERT_BEFORE
        value: # lua filter specification
          name: envoy.lua
          typed_config:
            "@type": "type.googleapis.com/envoy.config.filter.http.lua.v2.Lua"
            inlineCode: |
              function envoy_on_request(request_handle)
                -- Make an HTTP call to an upstream host with the following headers, body, and timeout.
                local headers, body = request_handle:httpCall(
                 "lua_cluster",
                 {
                  [":method"] = "POST",
                  [":path"] = "/acl",
                  [":authority"] = "internal.org.net"
                 },
                "authorize call",
                5000)
              end
    # The second patch adds the cluster that is referenced by the lua code
    # cds match is omitted as a new cluster is being added
    - applyTo: CLUSTER
      match:
        context: SIDECAR_OUTBOUND
      patch:
        operation: ADD
        value: # cluster specification
          name: "lua_cluster"
          type: STRICT_DNS
          connect_timeout: 0.5s
          lb_policy: ROUND_ROBIN
          hosts:
            - socket_address:
                protocol: TCP
                address: "internal.org.net"
                port_value: 8888

@lucasponce lucasponce added the do not merge A PR is not ready to merge label Aug 28, 2020
@lucasponce lucasponce changed the title Add IstioConfig under Workload Add IstioConfig under Workload Details Aug 28, 2020
@lucasponce lucasponce added requires server PR A PR sent to the frontend kiali/kiali-ui requires changes on backend kiali/kiali and removed do not merge A PR is not ready to merge labels Aug 31, 2020
Copy link
Contributor

@hhovsepy hhovsepy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When there is any broken Sidecar (with non exisint workload selector label), all the workloads get warning icon in Istio Config tab.
Also the Status column is too wide, and the Name column can be wider.
Screenshot from 2020-09-01 12-06-58
Screenshot from 2020-09-01 12-07-15
Screenshot from 2020-09-01 12-07-32
Screenshot from 2020-09-01 12-08-41

@lucasponce
Copy link
Contributor Author

@hhovsepy I've fixed the icon problem.

But the column is more tricky due the change should be in the PF4 component, so for that, I've re-arranged the columns, to put a 10% on the first of all of them, otherwise columns would like different.

So, with the change we'll have:

image
image
image
image
image

I've tested several options and no one is 100% good, so, at the moment you put a different % in a middle component, columns tend to have different aspect.

So, in short widths:

image

With the PF auto-layout:
image

So, let me know what do you think.

@hhovsepy hhovsepy self-requested a review September 1, 2020 14:43
Copy link
Contributor

@hhovsepy hhovsepy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified the warning icon and the layout. Much better now @lucasponce thank you.
Screenshot from 2020-09-01 16-42-38
Screenshot from 2020-09-01 16-43-59
Screenshot from 2020-09-01 16-44-10
Screenshot from 2020-09-01 16-44-28

Copy link
Member

@xeviknal xeviknal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! There is one comment I'd like to hear from @lucasponce

let istioConfigIcon = undefined;
if (this.state.workloadIstioConfig?.validations) {
const typeNames: { [key: string]: string[] } = {};
if (this.state.workloadIstioConfig.validations['gateway']) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is probably style, but do you think it is a way to do this if/else statements shorter not repeating code?
I guess that using dynamic access to objects of JS/TS could help reduce the number of lines of code.
this.state.workloadIstioConfig["envoyFilters"].forEach() could work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good comment, on this side I think this would work.

if (this.state.workloadIstioConfig?.validations) {
const typeNames: { [key: string]: string[] } = {};
if (this.state.workloadIstioConfig.validations['gateway']) {
this.state.workloadIstioConfig.gateways?.forEach(gw => typeNames['gateway'].push(gw.metadata.name));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the other if statements, you set the typeNames to an empty array. The lack of it for the gateways is intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's filtering in the UI side the validations that belongs to the Istio Config resources that are linked with a Workload.
So an empty names array is part of the logic.

: object && !object.valid && warnChecks > 0
? ValidationTypes.Warning
: ValidationTypes.Correct;
return errChecks > 0 ? ValidationTypes.Error : warnChecks > 0 ? ValidationTypes.Warning : ValidationTypes.Correct;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it simplifies the logic. Good catch.

Copy link
Member

@xeviknal xeviknal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@lucasponce lucasponce merged commit 9fe088c into kiali:master Sep 2, 2020
@ghost ghost added this to the v1.24.0 milestone Sep 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
requires server PR A PR sent to the frontend kiali/kiali-ui requires changes on backend kiali/kiali
Projects
None yet
3 participants