/srv/irclogs.ubuntu.com/2020/08/19/#smooth-operator.txt

drewn3ssLeaving a note here for anyone that can answer by tomorrow.  I'm trying to provide relation information in an operator framework charm and am getting hung up.  The interface is "promethus", and here's the old reactive class: https://git.launchpad.net/interface-prometheus/tree/provides.py#n28  I'm trying to write this into my helper library as:01:34
drewn3sshttps://git.launchpad.net/~afreiberger/charm-cloudstats/tree/lib/lib_cloudstats.py?h=feature/public-charm#n12601:34
drewn3ssrelation.data[hookenv.unit_name()]['extended_data'] = {"some-data"} is failing on key error for hookenv.unit_name() and I'm betting I'm just misunderstanding the data model for Relation.01:36
=== Dmitrii-Sh9 is now known as Dmitrii-Sh
stubhttps://github.com/canonical/interface-pgsql is (finally) there, but I was wondering about naming08:38
stubMaybe the repo should be called opslib-pgsql08:38
stubI'm also thinking that unless future stuff on the roadmap relies on it, ops.lib.use() is not going to be helpful now we have charmcraft assembling a venv08:40
Chipacastub: how so?08:41
stub(that branch supports both traditional 'import pgsql' syntax as well as ops.lib.use())08:41
Chipacastub: huzzah on the interface being there finally :)08:42
stubPer the example in the README.md, to use my library you can just declare it in requirements.txt and do 'import pgsql'.08:42
Chipacaok08:42
stubOr you can declare it in requirements.txt and do 'pgsql = ops.lib.use(...)'08:42
Chipacastub: yup :)08:43
Chipacastub: it's fine, for now i'd recommend people go the opslib route so we explore it a bit more, but if in the end it doesn't fill a need we can easily drop it and move on08:43
stubI'd like to update the docs to just have whatever we officially prefer, and decode between interface-pgsql and opslib-pgsql (so I can upload to pypi and remove the git URL from requirements.txt)08:43
stuback08:44
stubI'll await opinions on naming the repo and python module before switching our charms over.08:55
bthomasChipaca: refactored to ops-lib-k8s and pushed. Worked like a "charm" . Am using get_pod_status but will look into other minor refactorings along with switch to PodStatus.for_charm() .09:23
bthomasalso ops-lib-k8s does fail tests when built with pybuild but not pip3 install. Have not looked into it.09:23
Chipacabthomas: ack09:30
Chipacabthomas: what is pybuild09:30
Chipaca:)09:30
bthomas:) portability is good for the soul. Had a very quick but not through look. It is because setup.py file is not being found in the test setup. I suppose this can be fixed with some type of argument to pybuild but I am avoiding this distraction now. Want to focus on learning deployment with oci images.09:32
stubdrewn3ss: hookenv.unit_name() failing with a KeyError sounds like the JUJU_UNIT environment variable isn't set.10:01
stubdrewn3ss: In an event handler passed event 'ev',  I think you want """ ev.relation.data[self.model.unit]['extended_data'] = "data" """10:05
mupIssue operator#365 closed: Make JujuVersion.from_environ return 0,0,0 if JUJU_VERSION isn't set <Created by chipaca> <Closed by chipaca> <https://github.com/canonical/operator/issues/365>10:26
mupPR operator#379 closed: Assume version 0.0.0 if JUJU_VERSION is not set <Created by dstathis> <Merged by chipaca> <https://github.com/canonical/operator/pull/379>10:26
mupPR operator#380 closed: Add info about fixing pyyaml in README.md <Created by dstathis> <Merged by chipaca> <https://github.com/canonical/operator/pull/380>10:58
drewn3ssstub: thanks...I think after ruminating on it, that the helper being outside the operator's class is working against me, because, as you note, I need self.model.unit. (which I suppose I can pass to the helper, but may not be in the spirit of things)12:49
bthomasI am trying to understand what this jujug debug-log error implies "application-prometheus: 14:00:24 ERROR juju.worker.uniter.operation hook "install" (via hook dispatching script: dispatch) failed: exit status 1" .13:08
bthomasNote there is no install hook in the prometheus charm13:08
Chipacabthomas: dispatch failed13:11
bthomasChipaca: you mean dispatching "install" hook ?13:11
Chipacabthomas: no i mean you have a 'dispatch' binary, so it's called for every hook13:11
Chipacabthomas: and that has failed13:11
drewn3ssbthomas: what's the rest of the traceback before the exit status 1?13:28
drewn3ssdispatch always calls your charm.py entrypoint and sets observable bits like self.on.install in this case13:29
bthomasdrewn3ss: https://pastebin.com/6ie9jez913:29
bthomasthanks.13:30
drewn3ssYou may want to run debug-hooks and run the dispatch yourself to see what's happening on stdout.13:30
drewn3sswhatever's happening isn't getting hookenv logged.13:31
bthomasthanks was not aware of debug-hooks. will try.13:31
drewn3ssor juju run -u <unit> "hooks/install"13:33
drewn3sswhich should call into dispatch13:33
drewn3ssand send you stdout/err13:33
drewn3ssbtw, how do we call dispatch with the proper args, or does it have to be called from a wrapper so argv[0] is the right hook name?13:35
bthomasthis is the dispatch script : "JUJU_DISPATCH_PATH="${JUJU_DISPATCH_PATH:-$0}" PYTHONPATH=lib:venv ./src/charm.py"13:36
bthomasthanks for the debuggin tips. much appreciated.13:36
drewn3ssnp13:36
bthomasI should have mentioned I am deploying on a microk8s cluster. I just found out that juju deploy-hooks is not supported on k8s models.13:48
moon127juju deploy-logs from another terminal was helpful debugging k8s charms for me, the hook tracebacks appear in those logs.13:49
bthomasthank you13:50
facubatistaChipaca, justinclark, what's promised from my last branch: https://github.com/canonical/charmcraft/pull/12313:50
mupPR charmcraft#123: Show paths with str, not repr, as the latter is horrible in windows <Created by facundobatista> <https://github.com/canonical/charmcraft/pull/123>13:50
facubatistabthomas, justinclark, drewn3ss, please remember about https://github.com/canonical/charmcraft/pulls and https://github.com/canonical/operator/pulls (feel free to shout here which one are you tackling so you don't step over each other... we do not need a zillion reviews on each PR, so let's coordinate)14:27
facubatistaChipaca, ^14:27
justinclarkfacubatista: will do14:31
facubatistajustinclark, thanks14:31
facubatistaChipaca, from what we spoke recently: https://github.com/canonical/charmcraft/issues/12514:31
facubatistaChipaca, also, https://github.com/canonical/charmcraft/issues/126 and https://github.com/canonical/charmcraft/issues/12714:36
facubatistaChipaca, and finally, https://github.com/canonical/charmcraft/issues/12814:41
facubatista(what a morning!!)14:42
Chipacafacubatista: ...teté14:42
facubatistajajaj14:43
Chipacafacubatista: "what a morning, tea-tea", i guess?14:44
facubatistano, no, its not "ti ti"14:45
* facubatista needs to start writing phonetics14:45
* bthomas 14:46
* bthomas 😕14:47
Chipacabthomas: ?15:16
bthomasI was trying to deciper spanish :)15:25
Chipacafacubatista: stand up!15:31
facubatistaoops15:31
Chipacajustinclark: so, starting from Dmitrii-Sh's https://github.com/dshcherb/cockroachdb-operator you can see it uses https://github.com/dshcherb/interface-tcp-load-balancer which isn't exactly what you mentioned but might help?15:44
ChipacaI thought Dmitrii-Sh also wrote a generic 'http' interface but can't see it now15:44
justinclarkThanks Chipaca. I'll look over this. Also, for a bit more context, I'm trying to get the host and port for an incoming relation (via an http interface). Here's the exact line I'm trying to decouple from k8s: https://github.com/charmed-lma/charm-k8s-grafana/blob/88006babe566f3dd04d24dc183d3af40f242e82f/src/interface_http.py#L11215:49
Dmitrii-ShChipaca: I had some HTTP health-checking-related code in the TCP load-balancer interface since just checking socket establishment wasn't enough but not the HTTP interface unfortunately.15:53
dstathis@chipaca Do you know about pathlib? I think it could have been useful for some of these Windows fixes15:58
drewn3ssjustinclark: looking at line 104, and your todo, event.relation is the current event's relation handle.16:04
drewn3ssyou don't have to get_relations if you're in the relation event16:04
justinclarkThanks drewn3ss. I'm actually rewriting this entire charm from scratch but hoping to at least take some nice tidbits from that version. My goal is to get the host/port of the incoming relation in a way that will work for k8s and non-k8s charms.16:07
drewn3sshttps://pastebin.canonical.com/p/NJtNPQ9WSv/16:07
drewn3ssack, not sure about how k8s may throw a wrench in there, but this is how I'm consuming a very simple http interface ^16:08
justinclarkOh this looks helpful drewn3ss. Still getting up to speed on the framework as a whole -- would you be willing to share what your http interface looks like? I'm trying to learn by example at the moment :)16:12
drewn3sshow do you mean, what it looks like?  The relation data for "http" is defined as "private-address": <remote unit's address hosting the website>, "port": <port website is listening on>, AFAIK16:14
drewn3ssI'm only consuming a single website on the interface, so I'm not trying to build a loadbalancer.16:14
drewn3ssthe website in my code is the prometheus:website provides interface16:14
justinclarkI believe that answers my question. Thanks!16:16
drewn3sshttps://pastebin.canonical.com/p/pp9Gg3z6dZ/16:17
drewn3sscloudstats/0 is the "requires: website" charm, and prometheus2/0 is the "provides:website" charm16:17
drewn3ssthe code above is from cloudstats16:17
drewn3ssI guess technically ingress-adress should be referred before private-address16:18
drewn3ssbut all relations have private-address by virtue of the framework16:18
justinclarkThat's exactly the information I wasn't aware of. Perfect. Thanks again drewn3ss.16:20
mupIssue operator#386 opened: Add best practice suggestions into docs <Created by balbirthomas> <https://github.com/canonical/operator/issues/386>16:28
Chipacadstathis: yeah we use pathlib extensively, that's why the windows fixes aren't completely overwhelmed by path changes17:47
Chipacadstathis: not as extensively as we'd like because in 3.5 it wasn't as integrated as it is from 3.6 on17:47
Chipacabut still :)17:47
deejChipaca: So I was double checking a couple things after addressing your comments on that MP and it looks like the latest charmcraft release breaks interfaces in the build step?19:52
deeji.e. I suddenly have a build/lib/interfaces/pgsql/ directory that's empty instead of a symlink to the real interface19:52
Chipacadeej: latest from edge?19:53
deejThe snap, so not the latest latest19:53
Chipacadeej: right, but the snap from edge channel, or beta?19:54
deejAh, edge, yes19:54
Chipacadeej: alternatively, what does 'charmcraft version' say19:54
deejr4219:54
Chipacaah19:54
Chipacafacubatista: ^^^19:54
Chipacafacubatista: we broke something19:54
deejVersion: 0.3.1+38.g9f241a819:54
facubatistadeej, can you please do a "ls -l" of the original file, and provide us with the build log (you can see it wiht -v)19:56
facubatista?19:56
facubatistadeej, thanks19:56
deejSure, one sec19:57
deejfacubatista: https://pastebin.canonical.com/p/3Qrg2jwmP9/19:58
facubatistadeej, and what is? mod/interface-pgsql/pgsql/20:01
facubatistadoes that exist?20:01
deejhttps://pastebin.canonical.com/p/WtmZHdpzYd/20:01
deejIt does20:01
facubatistaah, oh20:01
facubatistammm20:01
facubatistadeej, Chipaca, I found the issue... we're asking first if it's a dir, before if it's a symlink20:03
Chipacafacubatista: you mean walk gives you symlinks to dirs in dirnames?20:05
facubatistaChipaca, mmm... well, is_dir() answers True20:07
facubatistaChipaca, and yes, just confirmed20:08
* Chipaca hugs deej20:08
Chipacathanks20:08
facubatista(that os.walk gives it in the dirnames)20:08
Chipacafacubatista: ok. I presume you're working on a fix? if so @ me when you've got a PR20:08
facubatistaChipaca, I am, yes20:09
Chipacak20:09
Chipacai'm over there in the corner reading some stuff20:09
deejHeh20:13
crodriguezHello hello. I'm trying to understand better the concept of units in kubernetes with juju.  When I deploy an app with juju, in the juju status, a unit "app/0" appears. The charm code executes in that "unit". Is that the equivalent of the app-operator-0 pod that appears in kubernetes? So the charm code actually runs in the operator pod?20:17
crodriguezThe reason of this question is that I am trying to use the kubernetes API in the charm. For that, I need to load the cluster config, and when I do it manually in the operator pod , it works, but when I run it in the charm, it fails with this :20:18
crodriguez```application-metallb-controller: 12:41:16 ERROR juju.worker.uniter.operation hook "install" (via hook dispatching script: dispatch) failed: exit status 120:18
crodriguezapplication-metallb-controller: 12:43:56 DEBUG unit.metallb-controller/0.install Traceback (most recent call last):20:18
crodriguezapplication-metallb-controller: 12:43:56 DEBUG unit.metallb-controller/0.install   File "./src/charm.py", line 20, in <module>20:18
crodriguezapplication-metallb-controller: 12:43:56 DEBUG unit.metallb-controller/0.install     class MetallbCharm(CharmBase):20:18
crodriguezapplication-metallb-controller: 12:43:56 DEBUG unit.metallb-controller/0.install   File "./src/charm.py", line 130, in MetallbCharm20:18
crodriguezapplication-metallb-controller: 12:43:56 DEBUG unit.metallb-controller/0.install     config.load_incluster_config()20:18
crodriguezapplication-metallb-controller: 12:43:56 DEBUG unit.metallb-controller/0.install   File "/var/lib/juju/agents/unit-metallb-controller-0/charm/venv/kubernetes/config/incluster_config.py", line 93, in load_incluster_config20:18
crodriguezapplication-metallb-controller: 12:43:56 DEBUG unit.metallb-controller/0.install     InClusterConfigLoader(token_filename=SERVICE_TOKEN_FILENAME,20:18
crodriguezapplication-metallb-controller: 12:43:56 DEBUG unit.metallb-controller/0.install   File "/var/lib/juju/agents/unit-metallb-controller-0/charm/venv/kubernetes/config/incluster_config.py", line 45, in load_and_set20:18
crodriguezapplication-metallb-controller: 12:43:56 DEBUG unit.metallb-controller/0.install     self._load_config()20:19
crodriguezapplication-metallb-controller: 12:43:56 DEBUG unit.metallb-controller/0.install   File "/var/lib/juju/agents/unit-metallb-controller-0/charm/venv/kubernetes/config/incluster_config.py", line 51, in _load_config20:19
crodriguezapplication-metallb-controller: 12:43:56 DEBUG unit.metallb-controller/0.install     raise ConfigException("Service host/port is not set.")20:19
crodriguezapplication-metallb-controller: 12:43:56 DEBUG unit.metallb-controller/0.install kubernetes.config.config_exception.ConfigException: Service host/port is not set.```20:19
crodriguezmmh sorry, I'll put that in a pastebin20:19
crodriguezhttps://pastebin.canonical.com/p/B77mMm4tYw/20:19
crodriguezSo, it seems to me that the charm does not run in the operator pod... so where does it? Just trying to figure this out20:19
Chipacacrodriguez: in the pod list you should be seeing two pods20:22
crodriguezyeah, the app pod and the operator pod. Well, install is failing right now because of this so only operator pod is up20:27
Chipacacrodriguez: you'll have one <charm>-0, and one <charm>-operator-020:27
Chipacaright20:27
Chipacacrodriguez: the operator pod is the one that runs the charm20:27
crodriguezdoes it run in a virtual environment ? Because if I go into the operator pod, I can run the python commands just fine https://pastebin.canonical.com/p/VbC2kvbXDR/20:30
crodriguezbut running these same commands in the charm causes the error I linked  https://pastebin.canonical.com/p/B77mMm4tYw/20:30
drewn3sscrodriguez: looks like you didn't exec that venv you were in the directory of.20:31
crodriguezI couldn't find a bin/activate (:20:31
drewn3ssoh fun.20:31
drewn3sslook at the dispatch file for how python is called20:32
drewn3ssmaybe it might give a hint20:32
crodriguezgood idea20:32
Chipacait's _not_ a venv, fwiw20:32
Chipacait's just the libraries20:32
crodriguezit's a fake venv called venv? :P20:33
Chipacayes20:33
drewn3sslol20:33
drewn3ssawesome20:33
facubatistaChipaca, https://github.com/canonical/charmcraft/pull/13120:33
mupPR charmcraft#131: Respect the symlink even if it's a directory when building <Created by facundobatista> <https://github.com/canonical/charmcraft/pull/131>20:33
facubatistadeej, ^20:33
crodriguezmay I suggest a rename to "lib" ?20:33
Chipacacrodriguez: people are using lib for their own nefarious purposes :-p20:33
crodriguezaah man :P20:33
drewn3sslol...now that we all know :)20:34
Chipacabut yeah, maybe .lib or sth20:34
drewn3ssthe nice thing is, it acts as a venv for charm code library pathing purposes20:34
facubatistadrewn3ss, crodriguez, this is not the venv you're looking for  *does some jedi hand waving*20:34
drewn3ssXD20:34
crodriguezhahaha20:35
facubatistaChipaca, ".lib or sth" is a horrible directory name20:35
crodriguezok... so dispatch only has this here : https://pastebin.canonical.com/p/z2fwtnMqrt/20:35
Chipacafacubatista: make it .💩20:35
crodriguezfacubatista, but venv is confusing!20:36
facubatistacrodriguez, if you do "PYTHONPATH=venv python3" and then the import, it should work20:36
drewn3ssooh, lib is being added automatically by dispatch...that's handy to reduce all the import not at top errors \o/20:36
facubatistacrodriguez, for sure we can improve that20:36
Chipacai have to agree with crodriguez here :-|20:37
facubatista(we just need a better name)20:37
drewn3ssmy days of taking Chipaca seriously are certainly coming to a middle.20:37
crodriguezcharm-packages ?20:37
facubatistainstalled-python-libs20:37
Chipacadrewn3ss: there's a trick to knowing when i'm being serious and when i'm not20:37
* drewn3ss is going to take the p00p emoji as a sign.20:38
Chipacadrewn3ss: (presumably) (i don't know it myself)20:38
crodriguezlmao20:38
crodriguezthanks facubatista , trying that now20:38
Chipacafacubatista: how about something that says where this comes from? like 'reqs' (or 'requirements' or sth)20:38
facubatistadeps20:39
facubatistapydeps20:39
drewn3ssbtw, mad props to the operator team.  this stuff makes charming SO much easier.  no more finite-state-machine madness, and relation-state unit testing are killer apps.20:39
Chipacapsydeps20:39
* drewn3ss is usually a curmudgeon when it comes to having to learn yet-another-framework, but this one is well worth the (oddly rather low) effort20:40
Chipaca\o/20:40
drewn3ssI know, I know, let's call yet another thing that's not a wheel a /wheel20:40
crodriguezwell it works just as well, I can't reproduce what the charm is complaining about https://pastebin.canonical.com/p/VnJm9wWbRv/20:40
Chipacaooohh, we could call it somehting wheely and make them all wheels20:40
Chipacacrodriguez: :-(20:41
Chipacacrodriguez: want to share the charm so i can take a peek?20:42
crodriguezSure. It's an ugly baby right now though, I warn you20:43
Chipacai'll put on my charm grandma glasses; all charms will be beautiful20:43
crodriguezChipaca, https://github.com/camille-rodriguez/charm-metallb-controller20:44
crodriguezContext is that I have to write a charm for metallb for k8s. MetalLB is contained of a controller and a speaker, so I'll have a bundle of 2 charms. I'm just getting started with the controller. And I want to use the k8s API directly in the charm because the juju pod_spec is not able to create PodSecurityPolicies yet20:45
crodriguezChipaca, haha perfect20:45
Chipacacrodriguez: and you're importing kubernetes, which is part of the image the charm runs on?20:46
deejfacubatista: Awesome, ta20:47
crodriguezChipaca, I added this block here https://github.com/camille-rodriguez/charm-metallb-controller/blob/master/src/charm.py#L130 to test the k8s api yeah20:47
crodriguezI'm testing with microk8s rn20:49
Chipacaheh, error about envget20:50
crodriguezyeah sorry, pull again :)20:51
crodriguezI removed that crap 20 sec after sending you the link lol. You're too quick!20:51
Chipacathis upgrade loop is so tedious20:54
Chipacanow i got there20:57
crodriguez:) yeah  I usually just get rid of the app and redeploy... no upgrade for me haha20:58
* facubatista needs to eod21:00
crodriguezkenneth just shared this with me https://github.com/juju-solutions/bundle-cert-manager/blob/master/charms/cert-manager-webhook/reactive/webhook.py#L37-L5021:01
crodriguezapparently there's a bug in how the juju agent passes env variables to the charm21:01
Chipacaaha! this rings a bell21:02
* Chipaca edits src/charm.py inside the pod directly21:02
crodriguezI wonder if there's a bug open for this..21:05
Chipacacrodriguez: that worked, fwiw21:06
Chipacacrodriguez: you know of the k8s opslib, yes?21:06
crodriguezgreat, I'm testing it rn too21:08
crodriguezI knew there was a k8s lib under your personal github, I thought that it was not ready yet21:09
Chipacacrodriguez: it's very minimal, just what mark maglana created with some tweaks, but ¯\_(ツ)_/¯21:09
Chipacait certainly doesn't know about PodSecurityPolicies :-D21:09
crodriguezhaha :P21:10
Chipacabut maybe it should include this hack until juju fixes it21:10
crodriguezwell once my k8s charm is better defined, maybe I'll contribute to it21:10
crodriguezyeah true21:10
Chipacacrodriguez: do you know if there's a bug about this?21:11
crodriguezkenneth didn't respond when I asked about a bug #21:11
crodriguezI'll dig21:11
Chipacacrodriguez: i'll stick around a bit longer to try to catch what you dig up21:11
* Chipaca ← not working though21:12
crodriguezthe closest I can find is the one John raised a few days ago for another problem I got lol https://bugs.launchpad.net/juju/+bug/189133721:14
crodriguezi don't think it's related to the metrics hooks specifically though. I might open a new bug21:15
crodriguezThere, a new one https://bugs.launchpad.net/juju/+bug/189225521:27
crodriguezthanks for your help :) have a great evening!21:35
Chipacacrodriguez: thanks!21:46

Generated by irclog2html.py 2.7 by Marius Gedminas - find it at mg.pov.lt!