*Following the progress on this task*
h4. Regards get the cluster IP and protocol automatically via ks8 api:
The following works when the project is executed with the command "make run-local" but not when the operator is deployed by the image, using the command "make create-all" the IP returned is not the master one.
* If it is running in a cluster the os.Getenv("KUBERNETES_SERVICE_HOST") has a value which is returned here and is not the value expected. ("https://172.30.0.1:443")
* When run locally, "outside of the cluster" the KUBERNETES_SERVICE_HOST is empty and the value expected is returned. ("https://192.168.64.19:8443")
{code:java} func getClusterProtocol() string { cfg, _:= config.GetConfig() cfgHost := cfg.Host cfgHost = strings.Replace(cfgHost, "//", "", 2) host := strings.Split(cfgHost, ":")
return host[0] }
func getHostIP() string { cfg, _:= config.GetConfig() cfgHost := cfg.Host cfgHost = strings.Replace(cfgHost, "//", "", 2) host := strings.Split(cfgHost, ":")
return host[1] }
{code} The same behaviour happened if we try to use the func `rest.InClusterConfig()` as follows.
{code:java} func getClusterProtocol() string { cfg, _:= rest.InClusterConfig() cfgHost := cfg.Host cfgHost = strings.Replace(cfgHost, "//", "", 2) host := strings.Split(cfgHost, ":") log.Info("Utils - ConfigHost", cfg.Host) return host[0] }
func getHostIP() string { cfg, _:= rest.InClusterConfig() cfgHost := cfg.Host cfgHost = strings.Replace(cfgHost, "//", "", 2) host := strings.Split(cfgHost, ":") log.Info("Utils - ConfigHost", cfg.Host)
return host[1] } {code}
h4. Tests with suggestion
* Tests doing exactly the same of the code suggested by [~weil] [here|https://github.com/linzhuangrong/prometheus-operator/blob/9874ab3427f7395b57b1fd696f24ca52ff928f55/test/framework/ingress.go#L24] * See [here|https://issues.jboss.org/browse/AEROGEAR-8990?focusedCommentId=13724577&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-13724577], the OCP did not create the router based on the ingress source generated. * Also, shows that this is just used to test the operator and not to expose the service on it. * Shows that prometheus is using the host as we are doing. See [here|https://github.com/linzhuangrong/prometheus-operator/blob/9874ab3427f7395b57b1fd696f24ca52ff928f55/helm/alertmanager/templates/ingress.yaml#L24] and asking for setup the host see [here|https://github.com/linzhuangrong/prometheus-operator/blob/9874ab3427f7395b57b1fd696f24ca52ff928f55/helm/grafana/README.md#L47] * Prometheus shows expose the services by shell too see [here|https://github.com/linzhuangrong/prometheus-operator/blob/9874ab3427f7395b57b1fd696f24ca52ff928f55/helm/grafana/templates/NOTES.txt#L11]
h4. Looking for examples.
* Integr8ly is informing the host as we are doing here. See [here|https://github.com/integr8ly/gitea-operator/blob/9b58cafe5e57b28606fafb569fbd0b2928021af2/templates/gitea-ingress.yaml#L10] and [here|https://github.com/integr8ly/gitea-operator/blob/9b58cafe5e57b28606fafb569fbd0b2928021af2/templates/gitea-config.yaml#L31]
* The WordPress operator shows request the domain definition for the host too. See [here|https://github.com/presslabs/wordpress-operator/blob/55cede40032a0f6a4188239cf394afc8dbcf6ba2/chart/wordpress-operator/templates/crds.yaml#L100] and [here|https://github.com/presslabs/wordpress-operator/blob/1d285e7cff886ac42fe88a9ec742b824b3c05e17/pkg/controller/wordpress/internal/sync/ingress.go#L66]
* This one is informing the domain too. [here|https://github.com/infinimesh/operator/blob/72eedaa87d5feb12eedc676fd38780c79593602e/pkg/controller/platform/apiserver_rest.go#L128] and [here|https://github.com/infinimesh/operator/blob/f77e95bc90f944af9197458a2e939149001a9e1c/config/samples/infinimesh_v1beta1_platform.yaml#L14]
* The vault.operator shows also requiring the host. See [here|https://github.com/coreos/vault-operator/blob/9f310f12f67d3080e16d1fa5dc0d345aa543a966/doc/user/tectonic/ingress.md#L3] and [here|https://github.com/coreos/vault-operator/blob/9f310f12f67d3080e16d1fa5dc0d345aa543a966/doc/user/tectonic/vault-ui.md#L40]
* The CrunchyData shows request to the user create the ingress/route manually. See [here|https://github.com/CrunchyData/postgres-operator/blob/7e867ebf211b488def26dfaf10d7b2b5bbd6f5f6/hugo/content/Installation/_index.md#pgo-cli-installation] *Conclusion: Shows that all operators are informing the host and it is a config value made by the user, or leading the steps to expose the service to the user by describing how to do it via README. Also, I could find a case where the expose of the service is made by running the shell command by the project which will install the operator instead of using the resources*
h4.NOTES:
* The following commands will return the master.
{code:java} $ kubectl config view -o jsonpath='{.clusters[0].cluster.server}'
$ oc status | grep server
$ kubectl cluster-info
$ kubectl cluster-info dump | grep -m 1 hostIP
{code}
* The command "kubectl config view" return the config file from kube (.kube/)
h4. Next Steps
* Raise questions in the repos to eng of operator-sdk and/or ocp to see know if we can find a great solution * If not: ( just improve it but keep is possible get the need to inform the hostname as all other oprators ) from inside of the cluster by the ks8 api. Shows that it is not possible currently. * Replace the name clusterIP for Hostname and describe on CR and README that it is the IP and/or the hostname to make clear * Create a shell script to get the clusterIP setup to do it and a make a command calling it. * Centralized the hostname spec in the mss CR * Updade the readme |
|