hawtio / hawtio-kubernetes

hawtio plugin for working with kubernetes
Apache License 2.0
24 stars 14 forks source link

provide a hawtio-forms UI by default when editing/viewing a ConfigMap if there is a json schema annotation #122

Closed jstrachan closed 7 years ago

jstrachan commented 7 years ago

we now attach a json schema via annotation fabric8.io/json-schema to a ConfigMap to help folks edit/generate them with default values, description, required and generate expressions etc

It'd be nice if the UI used those by default (rather than the YAML); though would be nice to still let folks go to the YAML too if they wish.

here's an example ConfigMap

kind: ConfigMap
apiVersion: v1
metadata:
  name: hubot-irc
  namespace: default
  selfLink: /api/v1/namespaces/default/configmaps/hubot-irc
  uid: 3626c7f6-607c-11e6-b2e2-8266870469e4
  resourceVersion: '110848'
  creationTimestamp: '2016-08-12T11:02:08Z'
  labels:
    group: io.fabric8.devops.apps
    project: hubot-irc
    provider: fabric8
    version: 2.2-SNAPSHOT
  annotations:
    description: >-
      Chat bot app using [Hubot](https://hubot.github.com/) and an IRC server to
      communicate with fabric8.
    fabric8.hubot-irc/iconUrl: >-
      https://cdn.rawgit.com/fabric8io/fabric8-devops/master/hubot-irc/src/main/fabric8/icon.png
    fabric8.hubot-irc/summary: '[Hubot](http://hubot.github.com) IRC chat bot'
    fabric8.io/json-schema: |-
      {
        "type" : "object",
        "properties" : {
          "HUBOT_IRC_USESSL" : {
            "type" : "string",
            "description" : "Use SSL",
            "default" : "1"
          },
          "HUBOT_GRAFANA_API_KEY" : {
            "type" : "string",
            "description" : "API key for a particular user"
          },
          "HUBOT_IRC_NICK" : {
            "type" : "string",
            "description" : "The name that hubot should joing the room as",
            "default" : "fabric8"
          },
          "HUBOT_IRC_DEBUG" : {
            "type" : "string",
            "description" : "Enables debug logging",
            "default" : "true"
          },
          "HUBOT_IRC_ROOMS" : {
            "type" : "string",
            "description" : "List of rooms to join including '#' prefix",
            "default" : "#fabric8_default,#random"
          },
          "HUBOT_GRAFANA_HOST" : {
            "type" : "string",
            "description" : "Host for your Grafana 2.0 install, e.g. 'http://play.grafana.org'"
          },
          "HUBOT_IRC_UNFLOOD" : {
            "type" : "string",
            "description" : "Unflood",
            "default" : "false"
          },
          "HUBOT_JENKINS_URL" : {
            "type" : "string",
            "description" : "The URL for the Jenkins CI server",
            "default" : "http://jenkins"
          },
          "HUBOT_IRC_SERVER" : {
            "type" : "string",
            "description" : "The IRC server",
            "default" : "irc.freenode.net"
          },
          "HUBOT_IRC_NICKSERV_PASSWORD" : {
            "type" : "string",
            "description" : "IRC nick password"
          },
          "HUBOT_IRC_PASSWORD" : {
            "type" : "string",
            "description" : "IRC password"
          }
        }
      }
data:
  hubot-grafana-api-key: ''
  hubot-grafana-host: ''
  hubot-irc-debug: 'true'
  hubot-irc-nick: fabric8
  hubot-irc-nickserv-password: ''
  hubot-irc-password: ''
  hubot-irc-rooms: '#fabric8_default,#random'
  hubot-irc-server: irc.freenode.net
  hubot-irc-unflood: 'false'
  hubot-irc-usessl: '1'
  hubot-jenkins-url: 'http://jenkins'
gashcrumb commented 7 years ago

Only issue I see currently is that the schema in your example doesn't match the keys in the object, so we'd have to do some extra work in the controller to copy the form values into the object once it's changed. If you had the schema like this (or have the keys in the data matching) there'd be less work in the controller:

kind: ConfigMap
apiVersion: v1
metadata:
  name: hubot-irc
  namespace: default
  selfLink: /api/v1/namespaces/default/configmaps/hubot-irc
  uid: 3626c7f6-607c-11e6-b2e2-8266870469e4
  resourceVersion: '110848'
  creationTimestamp: '2016-08-12T11:02:08Z'
  labels:
    group: io.fabric8.devops.apps
    project: hubot-irc
    provider: fabric8
    version: 2.2-SNAPSHOT
  annotations:
    description: >-
      Chat bot app using [Hubot](https://hubot.github.com/) and an IRC server to
      communicate with fabric8.
    fabric8.hubot-irc/iconUrl: >-
      https://cdn.rawgit.com/fabric8io/fabric8-devops/master/hubot-irc/src/main/fabric8/icon.png
    fabric8.hubot-irc/summary: '[Hubot](http://hubot.github.com) IRC chat bot'
    fabric8.io/json-schema: |-
      {
        "type" : "object",
        "properties" : {
          "hubot-irc-usessl" : {
            "type" : "string",
            "description" : "Use SSL",
            "default" : "1"
          },
          "hubot-grafana-api-key" : {
            "type" : "string",
            "description" : "API key for a particular user"
          },
          "hubot-irc-nick" : {
            "type" : "string",
            "description" : "The name that hubot should joing the room as",
            "default" : "fabric8"
          },
          "hubot-irc-debug" : {
            "type" : "string",
            "description" : "Enables debug logging",
            "default" : "true"
          },
          "hubot-irc-rooms" : {
            "type" : "string",
            "description" : "List of rooms to join including '#' prefix",
            "default" : "#fabric8_default,#random"
          },
          "hubot-grafana-host" : {
            "type" : "string",
            "description" : "Host for your Grafana 2.0 install, e.g. 'http://play.grafana.org'"
          },
          "hubot-irc-unflood" : {
            "type" : "string",
            "description" : "Unflood",
            "default" : "false"
          },
          "hubot-jenkins-url" : {
            "type" : "string",
            "description" : "The URL for the Jenkins CI server",
            "default" : "http://jenkins"
          },
          "hubot-irc-server" : {
            "type" : "string",
            "description" : "The IRC server",
            "default" : "irc.freenode.net"
          },
          "hubot-irc-nickserv-password" : {
            "type" : "string",
            "description" : "IRC nick password"
          },
          "hubot-irc-password" : {
            "type" : "string",
            "description" : "IRC password"
          }
        }
      }
data:
  hubot-grafana-api-key: ''
  hubot-grafana-host: ''
  hubot-irc-debug: 'true'
  hubot-irc-nick: fabric8
  hubot-irc-nickserv-password: ''
  hubot-irc-password: ''
  hubot-irc-rooms: '#fabric8_default,#random'
  hubot-irc-server: irc.freenode.net
  hubot-irc-unflood: 'false'
  hubot-irc-usessl: '1'
  hubot-jenkins-url: 'http://jenkins'
jstrachan commented 7 years ago

DOH! Lemme fix up the json schema so that the properties refer to the keys in data!

gashcrumb commented 7 years ago

Sounds good, I'll do it locally, am halfway through implementing this :-)

On Fri, Aug 12, 2016 at 11:14 AM, James Strachan notifications@github.com wrote:

DOH! Lemme fix up the json schema so that the properties refer to the keys in data!

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/hawtio/hawtio-kubernetes/issues/122#issuecomment-239473825, or mute the thread https://github.com/notifications/unsubscribe-auth/AAVdrB5Yle5KyBuWyafIqLOxBKk2Uxprks5qfI28gaJpZM4JjAr8 .

jstrachan commented 7 years ago

@gashcrumb yeah, its just toLowerCase().replace('_', '-') ;) but will fix up the JsonSchema's anyway soon!

jstrachan commented 7 years ago

awesome BTW!

jstrachan commented 7 years ago

Am migrating all the apps to use Deployment + ConfigMap for their configuration parameters (instead of OpenShift Templates) so that folks can reconfigure things at any time!

We'll also wanna look for ConfigMap's when Running stuff and let folks edit them in the UI before using the Run... UI (also taking into account any current existing ConfigMap of the same name)

gashcrumb commented 7 years ago

Hmm, it looks like suddenly angular has a problem with names like 'foo-bar' might be best to stick with camel case property names?

jstrachan commented 7 years ago

sounds good!

gashcrumb commented 7 years ago

Yeah, I think since we're using the name in an expresion angularjs interpretes kebab-case names as foo - bar, a subtraction expression! :-)

jstrachan commented 7 years ago

ah - no - has to be lower case in ConfigMap :(

I guess we could create a custom model that translates them; then swizzle them back again when writing to ConfigMap?

jstrachan commented 7 years ago

maybe we just replace '-', '_' internally first, then swizzle back again when we're about to write back to ConfigMap?

gashcrumb commented 7 years ago

balls yeah, I'll swizzle the data instead, don't change anything :-)