<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Other – TechBlog about OpenShift/Ansible/Satellite and much more</title><link>https://blog.stderr.at/categories/other/</link><description>TechBlog about OpenShift/Ansible/Satellite and much more</description><generator>Hugo 0.164.0</generator><language>en-us</language><copyright>Toni Schmidbauer &amp; Thomas Jungbauer</copyright><lastBuildDate>Fri, 10 Apr 2026 00:00:00 +0200</lastBuildDate><atom:link href="https://blog.stderr.at/categories/other/index.xml" rel="self" type="application/rss+xml"/><item><title>Creating a customized RHEL 10 VM image with image-builder</title><link>https://blog.stderr.at/other/2026-04-10-customize-rhel-image-builder/</link><guid isPermaLink="true">https://blog.stderr.at/other/2026-04-10-customize-rhel-image-builder/</guid><pubDate>Fri, 10 Apr 2026 00:00:00 +0200</pubDate><dc:creator>Articles by Toni Schmidbauer</dc:creator><category>Other</category><category>Virtualization</category><description>Creating a customized RHEL 10 VM image with image-builder</description><content:encoded><![CDATA[<div class="paragraph">
<p>In the blog post
<a href="https://blog.stderr.at/other/2026-04-09-macos-rhel10-bootc/">Creating a
RHEL 10 VM on macOS with bootc-image-builder</a> we described how to
quickly create a bootc (<a href="https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/using_image_mode_for_rhel_to_build_deploy_and_manage_operating_systems/introducing-image-mode-for-rhel">image mode</a>) base image on macOS. Now we would like to
create a customized standard RHEL image.</p>
</div>
<div class="paragraph">
<p>For this exercise we re-use an already provisioned RHEL 10.1 machine, the reasons for this are</p>
</div>
<div class="ulist">
<ul>
<li>
<p>We are going to use the <em>image-builder</em> command instead of <em>bootc
image builder</em>. If there is a container image providing this
command, please let us know</p>
</li>
<li>
<p>We are going to install packages which requires a subscribed RHEL
machine. A RHEL subscription for up to 16 machines is free of charge. You
just need to register at the <a href="https://developers.redhat.com/" rel="noopener" target="_blank">Red Hat developer</a> site.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>First we need to install required tools onto our RHEL 10.1 host:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ sudo dnf install -y image-builder</code></pre>
</div>
</div>
<div class="paragraph">
<p>Next we create a blueprint file to customize the resulting qcow2
image. We use the resulting image for a &#34;services&#34; machine, running
Unifi OS, Kea for DHCP and ISC bind (dns server):</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-toml hljs" data-lang="toml">name = &#34;services-rhel10&#34;
description = &#34;A VM running services&#34;
version = &#34;0.1&#34;

[[packages]]
name = &#34;podman&#34;
version = &#34;*&#34; <i class="conum" data-value="1"></i><b>(1)</b>

[customizations]
hostname = &#34;services&#34;

[[customizations.filesystem]]
mountpoint = &#34;/&#34;
minsize = &#34;50 GiB&#34; <i class="conum" data-value="2"></i><b>(2)</b>

[customizations.kernel]
append = &#34;ip=10.0.0.144::10.0.0.1:255.255.255.0:services:ens3:none:10.0.0.255&#34; <i class="conum" data-value="3"></i><b>(3)</b>

[[customizations.group]]
name = &#34;pinhead&#34;
gid = 1000

[[customizations.user]]
name = &#34;pinhead&#34;
password = &#34;&lt;password hash&gt;&#34; <i class="conum" data-value="4"></i><b>(4)</b>
key = &#34;&lt;ssh public key&gt;&#34; <i class="conum" data-value="5"></i><b>(5)</b>
home = &#34;/home/pinhead/&#34;
shell = &#34;/usr/bin/bash&#34;
groups = [&#34;users&#34;, &#34;wheel&#34;]
uid = 1000
gid = 1000

[[customizations.sshkey]]
user = &#34;root&#34;
key = &#34;&lt;public key&gt;&#34; <i class="conum" data-value="6"></i><b>(6)</b></code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tbody><tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>use the latest version of this package</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>resize the resulting image to 50GB</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>we configure a static ip address for this machine, our default interface is <em>ens3</em></td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>Enter the generated password hash here (see below)</td>
</tr>
<tr>
<td><i class="conum" data-value="5"></i><b>5</b></td>
<td>SSH public key to access this account</td>
</tr>
<tr>
<td><i class="conum" data-value="6"></i><b>6</b></td>
<td>SSH public key to access the root account</td>
</tr>
</tbody></table>
</div>
<div class="paragraph">
<p>To create a password hash use:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">python3 -c &#39;import crypt,getpass;pw=getpass.getpass();print(crypt.crypt(pw) if (pw==getpass.getpass(&#34;Confirm: &#34;)) else exit())&#39;</code></pre>
</div>
</div>
<div class="paragraph">
<p>For a detailed list of all customizations supported by <em>image-builder</em>
see the
<a href="https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/composing_a_customized_rhel_system_image/supported-image-customizations" rel="noopener" target="_blank">image builder customizations</a>
documentation.</p>
</div>
<div class="paragraph">
<p>As mentioned in the
<a href="https://blog.stderr.at/other/2026-04-09-macos-rhel10-bootc/" rel="noopener" target="_blank">previous article</a>
image builder provides the option to configure the resulting
image via kickstart. A builder for kickstart files is available here:</p>
</div>
<div class="paragraph">
<p><a class="bare" href="https://access.redhat.com/labs/kickstartconfig/">https://access.redhat.com/labs/kickstartconfig/</a></p>
</div>
<div class="paragraph">
<p>For a complete list of options see the <a href="https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/automatically_installing_rhel/kickstart-commands-and-options-reference" rel="noopener" target="_blank">kickstart documentation</a>.</p>
</div>
<div class="paragraph">
<p>One important note from the documentation (quoted):</p>
</div>
<div class="admonitionblock note">
<table>
<tbody><tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
The following combined customizations are not supported: [customizations.user] and [customizations.installer.kickstart]. When you add a Kickstart, use a configuration file in the TOML format, because multi-line strings are prone to error.
</td>
</tr>
</tbody></table>
</div>
<div class="paragraph">
<p>Now we are ready to run <em>image-builder</em>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">image-builder build qcow2 --distro rhel-10.1 --arch x86_64 --blueprint services-blueprint.toml</code></pre>
</div>
</div>
<div class="paragraph">
<p>The command above failed for us with the following error message:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-console hljs" data-lang="console">Failed to open file &#34;/sys/fs/selinux/checkreqprot&#34;: Read-only file system
imported gpg key
Signature check failed on sha256:9d0a71d87912a815f837f8427438936d6e9842834cc1f1062b90b2a41fbde594, lookup package name in manifest.
Traceback (most recent call last):
  File &#34;/run/osbuild/bin/org.osbuild.rpm&#34;, line 260, in &lt;module&gt;
r = main(args[&#34;tree&#34;], args[&#34;inputs&#34;], args[&#34;options&#34;])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File &#34;/run/osbuild/bin/org.osbuild.rpm&#34;, line 162, in main
subprocess.run([
  File &#34;/usr/lib64/python3.12/subprocess.py&#34;, line 571, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command &#39;[&#39;rpmkeys&#39;, &#39;--root&#39;, &#39;/run/osbuild/tree&#39;, &#39;--checksig&#39;, &#39;sha256:9d0a71d87912a815f837f8427438936d6e9842834cc1f1062b90b2a41fbde594&#39;]&#39; returned non-zero exit status 1.
Finished module org.osbuild.rpm
Finished pipeline build
manifest - failed
Output:
Failed</code></pre>
</div>
</div>
<div class="paragraph">
<p>According to <a href="https://access.redhat.com/solutions/7136467">this
knowledge base article</a> this is a bug in the current (2026-04-10)
version of image builder.</p>
</div>
<div class="paragraph">
<p>You can download an updated JSON file containing the missing RPM GPG
keys from the article. Drop the <em>RHEL-10.1</em> JSON file in a directory
and run <em>image-builder</em> again:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">image-builder --data-dir override/ build qcow2 --distro rhel-10.1 --arch x86_64 --blueprint services-blueprint.toml <i class="conum" data-value="1"></i><b>(1)</b></code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tbody><tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Use the <em>--data-dir</em> option and specify the folder with the <em>RHEL-10.1.json</em> file.</td>
</tr>
</tbody></table>
</div>
<div class="paragraph">
<p>You can find the resulting qcow image in the output directory under
<em>rhel-10.1-qcow2-x86_64/rhel-10.1-qcow2-x86_64.qcow2</em>.</p>
</div>
<div class="paragraph">
<p>A <em>Makefile</em> to streamline image creation can be found
<a href="https://codeberg.org/tosmi/playground/src/branch/master/rhel/image-builder/Makefile" rel="noopener" target="_blank">here</a>.</p>
</div>]]></content:encoded></item><item><title>Creating a RHEL 10 VM on macOS with bootc-image-builder</title><link>https://blog.stderr.at/other/2026-04-09-macos-rhel10-bootc/</link><guid isPermaLink="true">https://blog.stderr.at/other/2026-04-09-macos-rhel10-bootc/</guid><pubDate>Thu, 09 Apr 2026 00:00:00 +0200</pubDate><dc:creator>Articles by Toni Schmidbauer</dc:creator><category>Other</category><category>Virtualization</category><description>Creating a RHEL 10 VM on macOS with bootc-image-builder</description><content:encoded><![CDATA[<div class="paragraph">
<p>Yes, we have Apple machines in our lab because why not. So we needed a
RHEL 10 VM to set up Ansible Automation Platform, which seems to
support AARCH64 and Red Hat Enterprise Linux 10.</p>
</div>
<div class="paragraph">
<p>We need <a href="https://mac.getutm.app/" rel="noopener" target="_blank">UTM</a> installed on our Mac machine,
either
<a href="https://github.com/utmapp/UTM/releases/latest/download/UTM.dmg" rel="noopener" target="_blank">manually</a>,
via <a href="https://formulae.brew.sh/cask/utm" rel="noopener" target="_blank">Homebrew</a> or using a Nix
<a href="https://github.com/tosmi/nixos-config/blob/7faff0ed92d4bbefbef42641497cd2aa49c54b83/macos/fuji/flake.nix#L146" rel="noopener" target="_blank">flake</a>
(in order of increasing coolness).</p>
</div>
<div class="paragraph">
<p>Podman is also required, same rules as above apply:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="https://podman-desktop.io/" rel="noopener" target="_blank">manual installation</a></p>
</li>
<li>
<p><a href="https://formulae.brew.sh/cask/podman-desktop" rel="noopener" target="_blank">Homebrew</a></p>
</li>
<li>
<p><a href="https://github.com/tosmi/nixos-config/blob/3a6bc775d3164d080390590522956ad5399a34c6/macos/fuji/flake.nix#L147" rel="noopener" target="_blank">flake.nix</a></p>
</li>
</ul>
</div>
<div class="paragraph">
<p>We followed the
<a href="https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/using_image_mode_for_rhel_to_build_deploy_and_manage_operating_systems/creating-bootc-compatible-base-disk-images-by-using-bootc-image-builder" rel="noopener" target="_blank">RHEL documentation</a> for creating a bootable qcow image from a bootc
container image.</p>
</div>
<div class="paragraph">
<p>According to the <a href="https://github.com/osbuild/bootc-image-builder?tab=readme-ov-file#-installation" rel="noopener" target="_blank">upstream image builder docs</a>, we need to make sure
that our podman machine runs rootful. Otherwise image builder will not work. So let’s do this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ podman machine stop
$ podman machine set --rootful
$ podman machine start
$ podman machine info</code></pre>
</div>
</div>
<div class="paragraph">
<p>Next we need to pull the <em>bootc-image-builder</em> image:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ podman login registry.redhat.io <i class="conum" data-value="1"></i><b>(1)</b>
$ podman pull registry.redhat.io/rhel10/bootc-image-builder</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tbody><tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>This requires a valid Red Hat account. Registration is free of charge.</td>
</tr>
</tbody></table>
</div>
<div class="paragraph">
<p>Then we can pull the RHEL 10 bootc container, as <em>bootc-image-builder</em> is not able to pull container images:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">podman pull registry.redhat.io/rhel10/rhel-bootc:latest</code></pre>
</div>
</div>
<div class="paragraph">
<p>Image builder provides the option to configure the resulting image via
kickstart. A builder for kickstart files is available here:</p>
</div>
<div class="paragraph">
<p><a class="bare" href="https://access.redhat.com/labs/kickstartconfig/">https://access.redhat.com/labs/kickstartconfig/</a></p>
</div>
<div class="paragraph">
<p>For a complete list of options see the <a href="https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/10/html/automatically_installing_rhel/kickstart-commands-and-options-reference" rel="noopener" target="_blank">kickstart documentation</a>.</p>
</div>
<div class="paragraph">
<p>One important note from the documentation (quoted):</p>
</div>
<div class="admonitionblock note">
<table>
<tbody><tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
The following combined customizations are not supported: [customizations.user] and [customizations.installer.kickstart]. When you add a Kickstart, use a configuration file in the TOML format, because multi-line strings are prone to error.
</td>
</tr>
</tbody></table>
</div>
<div class="paragraph">
<p>For running the image builder we created a <a href="https://codeberg.org/tosmi/playground/src/branch/master/rhel/bootc/config.toml" rel="noopener" target="_blank"><em>toml</em> config file</a> to configure the final qcow image:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-toml hljs" data-lang="toml">[[customizations.user]]
name = &#34;pinhead&#34;
password = &#34;thepassword&#34;
key = &#34;ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIYhjnWzsArZVyyTa1E6sDbH06rUGDAhAF3bf3pmeBtm toni@stderr.at&#34;
groups = [&#34;wheel&#34;]

[[customizations.filesystem]]
mountpoint = &#34;/&#34;
minsize = &#34;50 GiB&#34;</code></pre>
</div>
</div>
<div class="paragraph">
<p>Now we are ready to trigger <em>bootc-image-builder</em>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">podman run \
    --rm \
    --privileged \
    --pull=newer \
    --security-opt label=type:unconfined_t \
    -v /var/lib/containers/storage:/var/lib/containers/storage \ <i class="conum" data-value="1"></i><b>(1)</b>
    -v ./config.toml:/config.toml:ro \
    -v ./output:/output \
    registry.redhat.io/rhel10/bootc-image-builder:latest \
    --type qcow2 \
    --config /config.toml \
  registry.redhat.io/rhel10/rhel-bootc:latest</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tbody><tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>We had to map this directory into the container, maybe this is required because we run podman in a VM on macOS (podman machine).</td>
</tr>
</tbody></table>
</div>
<div class="paragraph">
<p>You can find the resulting qcow image in the output directory under
<em>output/qcow2/disk.qcow2</em>. This image can be used to create a RHEL 10
VM in UTM on macOS.</p>
</div>
<div class="paragraph">
<p>It is also possible to customize the container image which is used as
an input for <em>bootc-image-builder</em>. But this requires a valid RHEL
subscription inside the container. The easiest way to achieve this is
by running bootc-image-builder on an already registered RHEL machine.</p>
</div>
<div class="paragraph">
<p>A <em>Makefile</em> to streamline image creation can be found <a href="https://codeberg.org/tosmi/playground/src/branch/master/rhel/bootc/Makefile" rel="noopener" target="_blank">here</a>.</p>
</div>]]></content:encoded></item><item><title>Helm Charts Repository Updates</title><link>https://blog.stderr.at/whats-new/2025-12-12-helm-charts-changelog/</link><guid isPermaLink="true">https://blog.stderr.at/whats-new/2025-12-12-helm-charts-changelog/</guid><pubDate>Fri, 12 Dec 2025 00:00:00 +0100</pubDate><dc:creator>Articles by Thomas Jungbauer</dc:creator><category>GitOps</category><category>Other</category><description>Latest updates and changes to the stderr.at Helm Charts collection for OpenShift and Kubernetes</description><content:encoded><![CDATA[<div class="paragraph">
<p>This page shows the <strong>latest updates</strong> to the <a href="https://blog.stderr.at/helm-charts">stderr.at Helm Charts Repository</a>.
The charts are designed for OpenShift and Kubernetes deployments, with a focus on GitOps workflows using Argo CD.</p>
</div>
<div class="admonitionblock note">
<table>
<tbody><tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
The content below is dynamically loaded from the Helm repository and always shows the most recent changes.
</td>
</tr>
</tbody></table>
</div>
<div class="paragraph">



<div id="helm-changelog-widget" class="helm-changelog" data-limit="10">
  <div class="helm-changelog-loading">
    <i class="fa fa-spinner fa-spin"></i> Loading latest Helm chart updates...
  </div>
</div>

<style>

</style>

<script defer src="/js/inline/helm-changelog.68008be7b909db146f4e9b677faf605681c58eb4d32c22fa20639af4109ae5a3.js"></script>

</div>
<div class="sect1">
<h2 id="_quick_links">Quick Links</h2>
<div class="sectionbody">
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 33.3333%;"/>
<col style="width: 66.6667%;"/>
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Resource</th>
<th class="tableblock halign-left valign-top">Link</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Helm Repository</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a class="bare" href="https://charts.stderr.at/">https://charts.stderr.at/</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">GitHub Source</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a class="bare" href="https://github.com/tjungbauer/helm-charts">https://github.com/tjungbauer/helm-charts</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">ArtifactHub</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a class="bare" href="https://artifacthub.io/packages/search?repo=tjungbauer">https://artifacthub.io/packages/search?repo=tjungbauer</a></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Example GitOps Repo</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><a class="bare" href="https://github.com/tjungbauer/openshift-clusterconfig-gitops">https://github.com/tjungbauer/openshift-clusterconfig-gitops</a></p></td>
</tr>
</tbody>
</table>
</div>
</div>]]></content:encoded></item><item><title>OpenShift Data Foundation - Noobaa Bucket Data Retention (Lifecycle)</title><link>https://blog.stderr.at/openshift-platform/day-2/storage/2024-02-12-bucket-data-retention/</link><guid isPermaLink="true">https://blog.stderr.at/openshift-platform/day-2/storage/2024-02-12-bucket-data-retention/</guid><pubDate>Mon, 12 Feb 2024 00:00:00 +0100</pubDate><dc:creator>Articles by Thomas Jungbauer</dc:creator><category>OpenShift</category><category>Other</category><description>How to configure a bucket lifecycle for Noobaa and OpenShift Data Foundation</description><content:encoded><![CDATA[<div class="paragraph">
<p>Data retention or lifecycle configuration for S3 buckets is done by the S3 provider directly. The provider keeps track and files are automatically rotated after the requested time.</p>
</div>
<div class="paragraph">
<p>This article is a simple step-by-step guide to configure such lifecycle for OpenShift Data Foundation (ODF), where buckets are provided by Noobaa. Knowledge about ODF is assumed, however similar steps can be reproduced for any S3-compliant storage operator.</p>
</div>
<div class="sect1">
<h2 id="_prerequisites">Prerequisites</h2>
<div class="sectionbody">
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Installed OpensShift 4.x cluster (latest version during the creation of this article 4.14)</p>
</li>
<li>
<p>Installed Open Data Foundation Operator (4.14+)</p>
</li>
<li>
<p>Configured Multi-Cloud Gateway (for example) to provide OpenShift with object storage.</p>
</li>
<li>
<p>Installed aws command line tool. The deployment for different operating system is explained at: <a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html#cliv2-linux-install">Installing AWS Client</a></p>
</li>
<li>
<p>A configured bucket and running openshift logging.</p>
</li>
</ol>
</div>
<div class="admonitionblock note">
<table>
<tbody><tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
In the further steps we use the bucket that is created for OpenShift Logging (using Lokistack) as a reference.
</td>
</tr>
</tbody></table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_working_with_aws_client">Working with aws client</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The first thing to do to work with the aws client is to retrieve the <strong>access key</strong> and <strong>secret key</strong> to be able to authenticate against the S3 API. During the deployment of OpenShift logging and the Lokistack a bucket has been created. The secret to authenticate against this bucket can be found in the openshift-logging namespace. In my example the name of this secret is <strong>logging-loki-s3</strong> and it contains the following values:</p>
</div>
<div class="imageblock">
<div class="content">
<img src="/openshift-platform/day-2/storage/images/lokisecret.png?width=220" alt="Loki Secret"/>
</div>
</div>
<div class="paragraph">
<p>The easiest way to authenticate against the S3 API is to create the following configuration file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">&gt; vim ~/.aws/credentials
[default]
aws_access_key_id     = &lt;value of access_key_id&gt;
aws_secret_access_key = &lt;value of access_key_secret&gt;</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tbody><tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Be sure that this file is not globally accessible.
</td>
</tr>
</tbody></table>
</div>
<div class="sect2">
<h3 id="_listing_objects">Listing Objects</h3>
<div class="paragraph">
<p>As a first test, we can try to list objects. The following command uses the S3 endpoint and the name of the bucket. Again, these values can be found in the Loki secret, mentioned above:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ aws --endpoint https://s3-openshift-storage.apps.ocp.local --no-verify-ssl s3 ls s3://logging-bucket-d39a258c-e971-4a0f-a1fa-302cb7e76a56
                           PRE application/
                           PRE audit/
                           PRE index/
                           PRE infrastructure/</code></pre>
</div>
</div>
<div class="paragraph">
<p>This command simply lists the current content (some folders in our case) of this bucket.</p>
</div>
</div>
<div class="sect2">
<h3 id="_copy_a_file_into_the_bucket">Copy a file into the bucket</h3>
<div class="paragraph">
<p>For further testing we copy a test file into the bucket. This can be any file, I have created an empty one called <strong>testfile.txt</strong></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ aws --endpoint https://s3-openshift-storage.apps.ocp.local --no-verify-ssl s3 cp testfile.txt s3://logging-bucket-d39a258c-e971-4a0f-a1fa-302cb7e76a56

upload: ./testfile.txt to s3://logging-bucket-d39a258c-e971-4a0f-a1fa-302cb7e76a56/testfile.txt</code></pre>
</div>
</div>
<div class="paragraph">
<p>Listing the content again, will now show the uploaded testfile.txt</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ aws --endpoint https://s3-openshift-storage.apps.ocp.local --no-verify-ssl s3 ls s3://logging-bucket-d39a258c-e971-4a0f-a1fa-302cb7e76a56
                           PRE application/
                           PRE audit/
                           PRE index/
                           PRE infrastructure/
2024-02-10 04:23:14         32 testfile.txt</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_verifying_current_lifecycle_configuration">Verifying current Lifecycle configuration</h3>
<div class="paragraph">
<p>To verify the current lifecycle configuration, execute the following command. It will show any configuration that is currently available, or an empty value if there is no such setting yet.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ aws --endpoint https://s3-openshift-storage.apps.ocp.local --no-verify-ssl s3api get-bucket-lifecycle-configuration --bucket logging-bucket-d39a258c-e971-4a0f-a1fa-302cb7e76a56</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_put_a_lifecycle_configuration_in_place">Put a lifecycle configuration in place</h3>
<div class="paragraph">
<p>To configure a data retention of 4 days for our bucket we first need to create the following JSON file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-json hljs" data-lang="json">cat logging-bucket-lifecycle.json
{
    &#34;Rules&#34;: [
        {
            &#34;Expiration&#34;: {
                &#34;Days&#34;: 4 <i class="conum" data-value="1"></i><b>(1)</b>
            },
            &#34;ID&#34;: &#34;123&#34;, <i class="conum" data-value="2"></i><b>(2)</b>
            &#34;Filter&#34;: {
                &#34;Prefix&#34;: &#34;&#34; <i class="conum" data-value="3"></i><b>(3)</b>
            },
            &#34;Status&#34;: &#34;Enabled&#34;
        }
    ]
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tbody><tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Defines the retention period is days.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>A simple ID for this Rule. (string).</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>A filter used to identify objects that a Lifecycle Rule applies to, here the filter is empty, so all objects are affected.</td>
</tr>
</tbody></table>
</div>
<div class="admonitionblock note">
<table>
<tbody><tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
There are much more setting possible as describe at <a href="https://docs.aws.amazon.com/cli/latest/reference/s3api/put-bucket-lifecycle-configuration.html">AWS S3API</a>.
</td>
</tr>
</tbody></table>
</div>
<div class="paragraph">
<p>The following command will put the defined rule in place:</p>
</div>
<div class="admonitionblock caution">
<table>
<tbody><tr>
<td class="icon">
<i class="fa icon-caution" title="Caution"></i>
</td>
<td class="content">
Already defined rules will be overwritten by the JSON file. If there have been previous configurations, put them into the JSON file as well.
</td>
</tr>
</tbody></table>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ aws --endpoint https://s3-openshift-storage.apps.ocp.local --no-verify-ssl s3api put-bucket-lifecycle-configuration --bucket logging-bucket-d39a258c-e971-4a0f-a1fa-302cb7e76a56 --lifecycle-configuration file://logging-bucket-lifecycle.json</code></pre>
</div>
</div>
<div class="paragraph">
<p>Checking again with the previous command, the rule should now be configured:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ aws --endpoint https://s3-openshift-storage.apps.ocp.local --no-verify-ssl s3api get-bucket-lifecycle-configuration --bucket logging-bucket-d39a258c-e971-4a0f-a1fa-302cb7e76a56</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_what_now">What now?</h3>
<div class="paragraph">
<p>Now you have to wait. With the configuration used above, it takes 4 days until the file is rotated. I have tested this using a 1 day retention period and saw that the file will be rotated after about 30 hours. So the rotation will not happen exactly at 24 hours but a bit afterwards.</p>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_consclusion">Consclusion</h2>
<div class="sectionbody">
<div class="paragraph">
<p>This article describes very, and I mean very, briefly how to configure such data retention for OpenShift Data Foundation. Unfortunately, public documentation can be confusing, so I summarized here the commands I have used.</p>
</div>
<div class="paragraph">
<p>There are some limitations with the Noobaa integration though. For example file transition (to a different storage class) is (currently) not supported.</p>
</div>
<div class="paragraph">
<p>Also, there are much more possible API calls that might be interesting. Please follow the AWS documentation:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><a href="https://docs.aws.amazon.com/cli/latest/reference/s3api/">S3 API</a></p>
</li>
<li>
<p><a href="https://docs.aws.amazon.com/cli/latest/reference/s3/">S3</a></p>
</li>
</ul>
</div>
</div>
</div>]]></content:encoded></item><item><title>Adventures in Java Land: JPA disconnected entities</title><link>https://blog.stderr.at/integrations/java/2022-02-25-jpa-disconnected-entity/</link><guid isPermaLink="true">https://blog.stderr.at/integrations/java/2022-02-25-jpa-disconnected-entity/</guid><pubDate>Fri, 25 Feb 2022 00:00:00 +0100</pubDate><dc:creator>Articles by Toni Schmidbauer</dc:creator><category>Other</category><description>An old man tries to refresh his Java skills and does DO378. He fails spectacularly at the first real example but learns a lot on the way.</description><content:encoded><![CDATA[<p>
An old man tries to refresh his Java skills and does <a href="https://www.redhat.com/en/services/training/red-hat-cloud-native-microservices-development-quarkus-do378">DO378</a>. He fails
spectacularly at the first real example but learns a lot on the way.</p>
<div id="outline-container-headline-1" class="outline-2">
<h2 id="headline-1">
The exception
</h2>
<div id="outline-text-headline-1" class="outline-text-2">
<p>
There is this basic example where you build a minimal REST API for
storing speaker data in a database. Quarkus makes this quite easy. You
just have to define your database connection properties in
<code>resources/application.properties</code> and off you go developing your Java
Quarkus REST service:</p>
<div class="src src-ini">
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-ini" data-lang="ini"><span class="line"><span class="cl"><span class="na">quarkus.datasource.db-kind</span><span class="o">=</span><span class="s">h2</span>
</span></span><span class="line"><span class="cl"><span class="na">quarkus.datasource.jdbc.url</span><span class="o">=</span><span class="s">jdbc:h2:mem:default</span>
</span></span><span class="line"><span class="cl"><span class="na">quarkus.datasource.username</span><span class="o">=</span><span class="s">admin</span>
</span></span><span class="line"><span class="cl"><span class="na">quarkus.hibernate-orm.database.generation</span><span class="o">=</span><span class="s">drop-and-create</span>
</span></span><span class="line"><span class="cl"><span class="na">quarkus.hibernate-orm.log.sql</span><span class="o">=</span><span class="s">true</span></span></span></code></pre></div>
</div>
<p>
So next we define our entity class to be stored in the database. I
will skip the import statements and any other code not relevant for
this post.</p>
<div class="src src-java">
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="line"><span class="cl"><span class="c1">// import statements skipped</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nd">@Entity</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">Speaker</span><span class="w"> </span><span class="kd">extends</span><span class="w"> </span><span class="n">PanacheEntity</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="n">UUID</span><span class="w"> </span><span class="n">uuid</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="n">nameFirst</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="n">nameLast</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="n">organization</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nd">@JsonbTransient</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="n">biography</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="n">picture</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="n">String</span><span class="w"> </span><span class="n">twitterHandle</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="c1">// Constructors, getters and setters, toString and other methods skipped</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">....</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span></span></span></code></pre></div>
</div>
<p>
We define an entity <code>Speaker</code> which extends the <a href="https://github.com/quarkusio/quarkus/blob/main/extensions/panache/hibernate-orm-panache/runtime/src/main/java/io/quarkus/hibernate/orm/panache/PanacheEntity.java"><code>PanacheEntity</code></a>
class. <a href="https://quarkus.io/guides/hibernate-orm-panache">Panache</a> is a thin wrapper around <a href="https://hibernate.org/">Hibernate</a> providing convince
features. For example the base class <code>PanacheEntity</code> defines a
autoincrement <code>Id</code> column for us. This inherited <code>Id</code> column is of
importance for understanding the problem ahead of us.</p>
<p>
So next you define your <code>SpeakerService</code> class which uses the
entity. Once again I will skip the imports and any code not relevant
for understanding the problem:</p>
<div class="src src-java">
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="line"><span class="cl"><span class="c1">// imports omitted</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nd">@ApplicationScoped</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">SpeakerService</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="c1">// other code omitted</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="n">Speaker</span><span class="w"> </span><span class="nf">create</span><span class="p">(</span><span class="n">Speaker</span><span class="w"> </span><span class="n">speaker</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="n">speaker</span><span class="p">.</span><span class="na">persist</span><span class="p">();</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="k">return</span><span class="w"> </span><span class="n">speaker</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">}</span></span></span></code></pre></div>
</div>
<p>
We focus on the <code>create</code> method here because the call to
<code>speaker.persist()</code> was the reason for all the headache.</p>
<p>
But we are still in coding mode and last but not least we define our
<code>SpeakerResource</code> class, again everything not relevant for
understanding the problem was removed:</p>
<div class="src src-java">
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="line"><span class="cl"><span class="c1">// import statements omitted</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nd">@Path</span><span class="p">(</span><span class="s">&#34;/speaker&#34;</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nd">@Produces</span><span class="p">(</span><span class="n">MediaType</span><span class="p">.</span><span class="na">APPLICATION_JSON</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nd">@Consumes</span><span class="p">(</span><span class="n">MediaType</span><span class="p">.</span><span class="na">APPLICATION_JSON</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">SpeakerResource</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nd">@Inject</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">SpeakerService</span><span class="w"> </span><span class="n">service</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="c1">// other code omitted</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nd">@POST</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nd">@Transactional</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="n">Speaker</span><span class="w"> </span><span class="nf">create</span><span class="p">(</span><span class="n">Speaker</span><span class="w"> </span><span class="n">newSpeaker</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="n">service</span><span class="p">.</span><span class="na">create</span><span class="p">(</span><span class="n">newSpeaker</span><span class="p">);</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="k">return</span><span class="w"> </span><span class="n">newSpeaker</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span></span></span></code></pre></div>
</div>
<p>
The root path for our <code>SpeakerResource</code> is <span style="text-decoration: underline;">/speaker</span>. We inject the
<code>SpeakerService</code> and define a method <code>create()</code> for creating a <code>Speaker</code>. We
would like to be able to send <code>@Post</code> requests to this endpoint and <a href="https://javaee.github.io/jsonb-spec/">Jsonb</a>
or<a href="https://github.com/FasterXML/jackson"> Jackson,</a> whichever we currently prefer, will deserialize the JSON
body in a <code>Speaker</code> object for us.</p>
<p>
Splendid, time to switch from coding mode to testing.</p>
<p>
We launch that Quarkus application in developer mode</p>
<div class="src src-sh">
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-sh" data-lang="sh"><span class="line"><span class="cl">mvn quarkus:dev</span></span></code></pre></div>
</div>
<p>
Quarkus is so friendly and provides a swagger-ui in dev mode for testing
our endpoint. Super duper lets call the <code>create()</code> endpoint via Swagger:</p>
<p>
<img src="/integrations/java/images/swagger_post_500.png" alt="/integrations/java/images/swagger_post_500.png" title="/integrations/java/images/swagger_post_500.png" /></p>
<p>
Because we are lazy we accept the default Swagger provides for us and
just click <span style="text-decoration: underline;">Execute</span>.</p>
<p>
BOOM, 500 internal server error. And a beautiful Java exception:</p>
<div class="src src-text">
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">org.jboss.resteasy.spi.UnhandledException: javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: org.acme.conference.speaker.Speaker</span></span></code></pre></div>
</div>
<p>
What? Detached entity what does this mean and why?</p>
</div>
</div>
<div id="outline-container-headline-2" class="outline-2">
<h2 id="headline-2">
Enlightenment
</h2>
<div id="outline-text-headline-2" class="outline-text-2">
<p>
Behind the scenes <a href="https://hibernate.org">Hibernate</a> uses a so called EntityManager for
managing entities. An Entity can be in the following states when
managed by Hibernate:</p>
<ul>
<li>NEW: The entity object was just created and is not persisted to the database</li>
<li>MANAGED: The entity is managed by a running Session and all changes
to the entity will be propagated to the database. After call to
<code>entitymanager.persist()</code> or in our case <code>newSpeaker.persist()</code> the
entity is stored in the database and in the <code>managed</code> state.</li>
<li>REMOVED: The entity is removed from the database. And finally</li>
<li>DETACHED: The Entity was detached from the EntityManager, e.g. by
calling <code>entitymanager.detach()</code> or <code>entitymanager.close()</code>.</li>
</ul>
<p>See <a href="https://www.baeldung.com/hibernate-entity-lifecycle">this</a> blog for a way better explanation what is going on with
entity states.</p>
<p>
Ok, cool but why the hell is our <code>Speaker</code> entity in the <span style="text-decoration: underline;">DETACHED</span>
state? It was just created and never saved to the database before!</p>
<p>
After checking the database (was empty), I started my Java debugger of
choice (IntellJ, but use whatever fit&#39;s your needs. I&#39;m to old for IDE
vs Editor and Editor vs Editor wars).</p>
<p>
So looking at the <code>Speaker</code> entity before calling <code>persist()</code> revealed the following:</p>
<p>
<img src="/integrations/java/images/speaker_object_debugger.png" alt="/integrations/java/images/speaker_object_debugger.png" title="/integrations/java/images/speaker_object_debugger.png" /></p>
<p>
The <code>Speaker</code> object passed into <code>create()</code> has an <span style="text-decoration: underline;">Id</span> of 0 and all
the internal Hibernate fields are set to null. So this seems to
indicate that this <code>Speaker</code> object is currently not attached to an
<code>EntityManager</code> session. This might explain the <strong>DETACHED</strong> state.</p>
<p>
I started playing around with <code>EntityManager</code> and calling <code>merge()</code> on the
speaker object. The code looked like this:</p>
<div class="src src-java">
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-java" data-lang="java"><span class="line"><span class="cl"><span class="nd">@ApplicationScoped</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">SpeakerService</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nd">@Inject</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="n">EntityManager</span><span class="w"> </span><span class="n">em</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="c1">// lots of code skipped</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="n">Speaker</span><span class="w"> </span><span class="nf">create</span><span class="p">(</span><span class="n">Speaker</span><span class="w"> </span><span class="n">speaker</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="kd">var</span><span class="w"> </span><span class="n">newSpeaker</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">em</span><span class="p">.</span><span class="na">merge</span><span class="p">(</span><span class="n">speaker</span><span class="p">);</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="n">newSpeaker</span><span class="p">.</span><span class="na">persist</span><span class="p">();</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="k">return</span><span class="w"> </span><span class="n">speaker</span><span class="p">;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">}</span></span></span></code></pre></div>
</div>
<p>
Looking at the <code>newSpeaker</code> object returned by calling <code>entitymanager.merge()</code>
in the debugger revealed the following:</p>
<p>
<img src="/integrations/java/images/speaker_object_entitymanager_debugger.png" alt="/integrations/java/images/speaker_object_entitymanager_debugger.png" title="/integrations/java/images/speaker_object_entitymanager_debugger.png" /></p>
<p>
<code>newSpeaker</code> has an Id of 1 (hm, why no 0?) and some those special
Hibernate fields starting with $$ have a value assigned. So for me
this indicates that the object is now managed by an <code>EntityManager</code>
session and in the <strong>MANAGED</strong> state.</p>
<p>
And the <code>Id</code>, already assigned to the original <code>Speaker</code> object,
de-serialized form JSON is actually the reason for the beautiful
exception above.</p>
</div>
</div>
<div id="outline-container-headline-3" class="outline-2">
<h2 id="headline-3">
Explanation
</h2>
<div id="outline-text-headline-3" class="outline-text-2">
<p>
So after a little bit of internet search magic I found an explanation
for the exception:</p>
<p>

<div class="admonitionblock important" ><table><tbody><tr><td class="icon"><i class="fa icon-important" title="important"></i></td><td class="content"><p>
If an <code>Id</code> is already assigned to an entity object, Hibernate assumes
that this is an entity in the <strong>DETACHED</strong> state (if the <span style="text-decoration: underline;">Id</span> is
auto-generated). For an entity to be persisted to the database it has
to be transferred in the <strong>MANAGED</strong> state by calling
<code>entitymanager.merge()</code></p>
<p>
For more information see the <a href="https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#pc">Hibernate documentation</a>.</p>
</td></tr></tbody></table></div>
</p>
<p>
We can only call <code>persist()</code> if the object is in the transient state,
to quote the <a href="https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#pc">Hibernate documentation</a>:</p>
<p>
<span style="text-decoration: underline;">transient</span>: the entity has just been instantiated and is not associated
with a persistence context. It has no persistent representation in the
database and <strong>typically no identifier value has been assigned (unless
the assigned generator was used)</strong>.</p>
<p>
And reading on we also get explanation for the detached state:</p>
<p>
<span style="text-decoration: underline;">detached</span>: <strong>the entity has an associated identifier</strong> but is no longer
associated with a persistence context (usually because the persistence
context was closed or the instance was evicted from the context)</p>
<p>
Just removing the <code>Id</code> from the POST request will solve the issue and
the example started to work.</p>
<p>
This is also why the <code>Id</code> column is different in the <code>Speaker</code> object
(deserialized from JSON) and <code>newSpeaker</code> object (create by calling
<code>entitymanager.merge()</code>). The <code>Speaker</code> <span style="text-decoration: underline;">Id</span> got passed in from JSON,
and has nothing to do with the auto generated primary key <span style="text-decoration: underline;">Id</span> within
our database. After calling <code>entitymanager.merge()</code> the entity is
actually associated with a database session and the <span style="text-decoration: underline;">Id</span> is
auto generated.</p>
<p>
So maybe this is basic stuff, but it took me quite a few hours to
understand what was going on.</p>
<p>
Maybe this is also a bad example. Should one expose the <code>Id</code> if it is
auto generated and only used internally? Or the code just needs to
handle that case… But this needs me more learning about API design.</p>
</div>
</div>]]></content:encoded></item><item><title>Basic usage of git</title><link>https://blog.stderr.at/integrations/general/2020/05/basic-usage-of-git/</link><guid isPermaLink="true">https://blog.stderr.at/integrations/general/2020/05/basic-usage-of-git/</guid><pubDate>Fri, 08 May 2020 00:00:00 +0200</pubDate><dc:creator>Articles by Toni Schmidbauer</dc:creator><category>Other</category><description>Using git for contributing to projects hosted on github.com</description><content:encoded><![CDATA[<div class="paragraph">
<p>This is a very short and hopefully simple introduction on how to use
<a href="https://git-scm.com/">Git</a> when you would like to contribute to
projects hosted on <a href="http://github.com">github.com</a>. The same workflow should also work for
projects on <a href="http://gitlab.com">gitlab.com</a>.</p>
</div>
<div class="sect1">
<h2 id="_introduction">Introduction</h2>
<div class="sectionbody">
<div class="paragraph">
<p>There is this fancy mega application hosted on github called
<a href="https://github.com/rhatservices/megaapp">megaapp</a> that you would like
to contribute to. It’s perfect but there’s just this little feature
missing to make it even more perfect.</p>
</div>
<div class="paragraph">
<p>This is how we would tackle this.</p>
</div>
<div class="admonitionblock warning">
<table>
<tbody><tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
rocket science ahead
</td>
</tr>
</tbody></table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_glossary">Glossary</h2>
<div class="sectionbody">
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 27.2727%;"/>
<col style="width: 72.7273%;"/>
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Term</th>
<th class="tableblock halign-left valign-top">Definition</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">fork</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">A (personal) copy of a repository you created on github or gitlab.</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">upstream</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">When creating forks of repositories on github or gitlab, the original repository hosting the project</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">index</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">The staging area git uses before you can commit to a repository</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">remote repository</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">A repository hosted on a server shared by developers</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">local repository</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">A local copy of a repository stored on you machine.</p></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="sect1">
<h2 id="_step_1_fork_the_repository_on_github_com">Step 1: Fork the repository on github.com</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Login to you Github account and navigate to the project you would like
to fork, <a href="https://github.com/rhatservices/megaapp">megaapp</a> in our
example.</p>
</div>
<div class="paragraph">
<p>Click on the the fork button, as depicted in the image below:</p>
</div>
<div class="imageblock">
<div class="content">
<img src="/integrations/general/images/fork.png" alt="fork"/>
</div>
</div>
<div class="paragraph">
<p>If you are a member of several projects on github.com, github is going
to ask you into which project you would like to clone this repository.</p>
</div>
<div class="paragraph">
<p>After selecting the project or your personal account, github is going
to clone the repository into the project you selected. For this
example I’m going to use my personal github account &#34;tosmi&#34;.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_step_2_clone_the_repository_to_you_workstation">Step 2: Clone the repository to you workstation</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Next we are going to clone our fork from <a href="#_step_1_fork_the_repository_on_github_com">Step 1: Fork the repository on github.com</a> to our workstation and start working on the new
feature.</p>
</div>
<div class="paragraph">
<p>After forking the upstream project you are redirect to your personal
copy of the project. Click on the &#34;Clone or download&#34; button and
select the link. You can choose between SSH and HTTPS protocols for
downloading the project. We are going to use SSH.</p>
</div>
<div class="imageblock">
<div class="content">
<img src="/integrations/general/images/clone.png" alt="clone"/>
</div>
</div>
<div class="paragraph">
<p>Copy the link into a terminal and execute the <em>git clone</em> command:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ git clone git@github.com:tosmi/megaapp.git</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_step_3_create_a_feature_branch_for_your_new_fancy_feature">Step 3: Create a feature branch for your new fancy feature</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Change into the directory of the project you downloaded in <a href="#_step_2_clone_the_repository_to_you_workstation">Step 2: Clone the repository to you workstation</a></p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">cd megaapp</code></pre>
</div>
</div>
<div class="paragraph">
<p>Now we create a feature branch with a short name that describes our new feature:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">git checkout -b tosmi/addoption</code></pre>
</div>
</div>
<div class="paragraph">
<p>Because we would like to add a new option to <em>megaapp</em> we call this feature branch <em>addoption</em>.</p>
</div>
<div class="paragraph">
<p>We are also prefixing the feature branch with our github username so that
it is clear for the upstream project maintainer(s) who is contributing this.</p>
</div>
<div class="paragraph">
<p>How you name you branches is opinionated, so we would search for
upstream project guidelines and if there are none maybe look at some
existing pull request how other people are naming there branches. If we
find no clue upstream we sticking with <em>&lt;github username&gt;/&lt;branch
name&gt;</em>.</p>
</div>
<div class="paragraph">
<p>We can now start adding our mega feature to the project.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_step_4_add_you_changes_to_the_git_index">Step 4: Add you changes to the Git index</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Before we can commit our changes, we have to place the changes made in
the so called <em>index</em> or staging area:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ git add &lt;path to file you have changed&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>If we would like to place all of our changes onto the index we could execute</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ git add -A</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_step_5_commit_your_changes">Step 5: Commit your changes</h2>
<div class="sectionbody">
<div class="paragraph">
<p>After adding our changes to the Git index we can commit with</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ git commit</code></pre>
</div>
</div>
<div class="paragraph">
<p>This will open our favorite editor and we can type a commit
message. The first line should be a short description of our change,
probably not longer than 70 to 80 characters. After two newlines we
can enter a detailed explanation of your changes.</p>
</div>
<div class="paragraph">
<p>This is an example commit message</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">Added a `version` option to output the current version of megaapp

This change introduces a `version` option to megaapp. The purpose is
to output the current version of megaapp for users. This might be
helpful when users open a bug report so we can see what version is
affected.</code></pre>
</div>
</div>
<div class="paragraph">
<p>After saving the message and we have successfully created a commit.</p>
</div>
<div class="admonitionblock note">
<table>
<tbody><tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Remember this is now only stored in the local copy of the
repository! We still have to push our changes to github.
</td>
</tr>
</tbody></table>
</div>
<div class="paragraph">
<p>There is also the option to add the commit comment directly on the command line</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ git commit -m &#39;Added a `version` option to output the current version of megaapp

This change introduces a `version` option to megaapp. The purpose is
to output the current version of megaapp for users. This might be
helpful when users open a bug report so we can see what version is
affected.&#39;</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_step_6_pushing_our_local_changes_to_our_forked_repo_on_github_com">Step 6: Pushing our local changes to our forked repo on github.com</h2>
<div class="sectionbody">
<div class="paragraph">
<p>We execute</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ git push</code></pre>
</div>
</div>
<div class="paragraph">
<p>to push our local changes to the forked repository hosted on github.com.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_step_7_creating_a_pull_request_on_github_com">Step 7: Creating a pull request on github.com</h2>
<div class="sectionbody">
<div class="paragraph">
<p>We navigate to our personal project page of the forked repository on
github. For the fork we are using in this example this is
<a class="bare" href="http://github.com/tosmi/megaapp">http://github.com/tosmi/megaapp</a>.</p>
</div>
<div class="paragraph">
<p>Github is going to show us a button &#34;Compare &amp; pull request&#34;:</p>
</div>
<div class="imageblock">
<div class="content">
<img src="/integrations/general/images/pull_request.png" alt="pull request"/>
</div>
</div>
<div class="paragraph">
<p>After clicking on that button we are able to review the changes we
would like to include in this pull request.</p>
</div>
<div class="paragraph">
<p>If we are happy with our changes we click on &#34;Create pull
request&#34;. The upstream owner of the repository will get notified and
we can see our open pull request on the upstream project page under
&#34;Pull requests&#34;.</p>
</div>
<div class="paragraph">
<p>If there are CI test configured for that project they will start to
run and we can see if our pull request is going to pass all test
configured.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_rebasing_to_current_upstream_if_required">Rebasing to current upstream if required</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Sometimes a upstream project maintainer asks you to rebase your work
on the current upstream master branch. The following steps explain the
basic workflow.</p>
</div>
<div class="paragraph">
<p>First we are going to create a new remote location of our repository
called <em>upstream</em>. <em>Upstream</em> points to the upstream project
repository. We will not push to this location, in most cases this is
not possible because you do not have write access to a remote upstream
repository. It is just used for pulling upstream changes in our forked
repository.</p>
</div>
<div class="paragraph">
<p>Execute the following commands to add the upstream repository as a new
remote location and display all remote locations currently defined.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ git remote add upstream https://github.com/rhatservices/megaapp.git
$ git remote -v origin
git@github.com:tosmi/megaapp.git (fetch) origin
git@github.com:tosmi/megaapp.git (push) upstream
https://github.com/rhatservices/megaapp.git (fetch) upstream
https://github.com/rhatservices/megaapp.git (push)</code></pre>
</div>
</div>
<div class="paragraph">
<p>As we hopefully implemented our new feature in feature branch, we can
pull changes from the upstream master branch into our local copy of
the master branch. Remember we are using a feature branch and master
should be kept clean from local changes.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ git checkout master
Switched to branch &#39;master&#39;
Your branch is up to date with &#39;origin/master&#39;.</code></pre>
</div>
</div>
<div class="paragraph">
<p>So now we have this older copy of the upstream master branch checked
out and we would like to update it to the latest and greatest from the
upstream master branch.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ git pull upstream master
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 6 (delta 2), reused 6 (delta 2), pack-reused 0
Unpacking objects: 100% (6/6), 630 bytes | 157.00 KiB/s, done.
From https://github.com/rhatservices/megaapp
 * branch            master     -&gt; FETCH_HEAD
 * [new branch]      master     -&gt; upstream/master
Updating 4d8584e..ddfd077
Fast-forward
 cmd/megaapp/main.go |  2 ++
 cmd/megaapp/rule.go | 20 ++++++++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 cmd/megaapp/rule.go</code></pre>
</div>
</div>
<div class="paragraph">
<p>With the pull command above you pulled all changes from the upstream
master branch into you local copy of master. Just to be sure let’s
display all available branches, local and remote ones.</p>
</div>
<div class="paragraph">
<p>Branches with a name <em>remote/&lt;remote name&gt;/&lt;branch name&gt;</em> are remote
branches that git knows about. <em>Origin</em> points to our forked
repository and is also the default location for push operations.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ git branch -a
  master
* tosmi/megafeature
  remotes/origin/HEAD -&gt; origin/master
  remotes/origin/master
  remotes/origin/tosmi/megafeature
  remotes/upstream/master</code></pre>
</div>
</div>
<div class="paragraph">
<p>So finally to <strong>rebase</strong> our feature branch to the upstream master
branch we first need to checkout our feature branch via</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ git checkout tosmi/megafeature</code></pre>
</div>
</div>
<div class="paragraph">
<p>Now we are able to rebase our changes to upstream master. Git
basically pulls in all changes from the master branch and re-applies
the changes we did in our feature branch.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">git rebase upstream/master
Successfully rebased and updated refs/heads/tosmi/megafeature.</code></pre>
</div>
</div>
<div class="paragraph">
<p>There might be merge conflicts when git tries to apply you changes
from your feature branch. You have to fix those changes, <em>git add</em> the
fixed files and execute <em>git rebase continue</em>. Luckily this is not the
case for your megafeature.</p>
</div>
<div class="paragraph">
<p>As we have successfully rebased our feature branch to upstream master
we can now try to push changes made to our forked github repository.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ git push
To github.com:tosmi/megaapp.git
 ! [rejected]        tosmi/megafeature -&gt; tosmi/megafeature (non-fast-forward)
error: failed to push some refs to &#39;git@github.com:tosmi/megaapp.git&#39;
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: &#39;git pull ...&#39;) before pushing again.
hint: See the &#39;Note about fast-forwards&#39; in &#39;git push --help&#39; for details.</code></pre>
</div>
</div>
<div class="paragraph">
<p>Oh, this fails of course! The reason is that our local feature branch
and the remote feature branch have a different commit history. The
remote feature branch is missing the commits from master that we
applied when rebasing on the current master branch.</p>
</div>
<div class="paragraph">
<p>So let’s try again, this time using the <em>--force-with-lease</em>
option. You could also use <em>-f</em> or <em>--force</em> but <em>--force-with-lease</em>
will stop you if someone else (our you) has modified the remote feature
branch meanwhile. If you  push with <em>-f</em> or <em>--force</em> anyways you might loose changes.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ git push --force-with-lease
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 295 bytes | 295.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:tosmi/megaapp.git
 + acf66a3...39357b2 tosmi/megafeature -&gt; tosmi/megafeature (forced update)</code></pre>
</div>
</div>
<div class="paragraph">
<p>But as no one modified the remote feature branch while we did our
rebase the force push goes through.</p>
</div>
<div class="paragraph">
<p>Our merge request (if we opened one already) is now updated to the
latest upstream master branch and merging our feature should be a
breeze. You might notify the upstream project maintainer that you
feature branch is up to date and ready for merging</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_using_gits_interactive_rebase_to_change_you_commit_history">Using git’s interactive rebase to change you commit history</h2>
<div class="sectionbody">
<div class="paragraph">
<p>When working with upstream projects it might be that a project
maintainer requests that you rework your git history before he is
willing to merge your changes. For example this could be that case if
you have plenty of commits with very small changes (e.g. fixed typos).</p>
</div>
<div class="paragraph">
<p>The general rule is that one commit should implement one change. This
is not a hard rule, but usually works.</p>
</div>
<div class="paragraph">
<p>Let’s look at an example. For the implementation of our new feature
that we would like to bring upstream we have the following commit history</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ git log --oneline
0a5221d (HEAD -&gt; tosmi/megafeature) fixed typo
0e60d12 update README
bf2ef3c update</code></pre>
</div>
</div>
<div class="paragraph">
<p>We have updated README.md in the repository but there a three commits
for this little change. Before bringing this upstream in our pull
request, we would like to convert those three commits into a single
one and also make the commit message a little more meaningful.</p>
</div>
<div class="paragraph">
<p>We execute the following command to start reworking our commit history</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ git rebase -i</code></pre>
</div>
</div>
<div class="paragraph">
<p>Git will drop us into our beloved editor (vi in this case), under
Linux you could change the editor git uses by modifying the $EDITOR
environment variable. We are going to see the following output:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">pick bf2ef3c update
pick 0e60d12 update README
pick 0a5221d fixed typo

# Rebase 39357b2..0a5221d onto 39357b2 (3 commands)
#
# Commands:
# p, pick &lt;commit&gt; = use commit
# r, reword &lt;commit&gt; = use commit, but edit the commit message
# e, edit &lt;commit&gt; = use commit, but stop for amending
# s, squash &lt;commit&gt; = use commit, but meld into previous commit
# f, fixup &lt;commit&gt; = like &#34;squash&#34;, but discard this commit&#39;s log message
# x, exec &lt;command&gt; = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with &#39;git rebase --continue&#39;)
# d, drop &lt;commit&gt; = remove commit
# l, label &lt;label&gt; = label current HEAD with a name
# t, reset &lt;label&gt; = reset HEAD to a label
# m, merge [-C &lt;commit&gt; | -c &lt;commit&gt;] &lt;label&gt; [# &lt;oneline&gt;]
# .       create a merge commit using the original merge commit&#39;s
# .       message (or the oneline, if no original merge commit was
# .       specified). Use -c &lt;commit&gt; to reword the commit message.
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#</code></pre>
</div>
</div>
<div class="paragraph">
<p>Git automatically selected commit id bf2ef3c as the basis for our
rebase. We could also have specified the commit id where we would like
to start our rebase operation e.g.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">git rebase -i bf2ef3c</code></pre>
</div>
</div>
<div class="paragraph">
<p>In our editor of choice we can now tell git what it should do with the selected commits.
Please go ahead and read the helpfull explanation text in comments (prefixed with &#39;#&#39;)
to get a better understanding of the operations supported.</p>
</div>
<div class="paragraph">
<p>In our case we would like to <em>squash</em> the last commits. So we change the lines with <em>pick</em> to
<em>squash</em> until it looks like the following:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">pick bf2ef3c update
squash 0e60d12 update README
squash 0a5221d fixed typo</code></pre>
</div>
</div>
<div class="paragraph">
<p>We would like to squash commits 0a5221d and 0e60d12 onto commit
bf2ef3c. Keep in mind that git actually reverses the order of
commits. So 0a5221d is the last commit we added.</p>
</div>
<div class="paragraph">
<p>If we save the file and quit our editor (I’m using vi here), git drops us into
another buffer where we can finally modify the commits</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash"> This is a combination of 3 commits.
# This is the 1st commit message:

update

# This is the commit message #2:

update README

# This is the commit message #3:

fixed typo

# Please enter the commit message for your changes. Lines starting
# with &#39;#&#39; will be ignored, and an empty message aborts the commit.
#
# Date:      Mon May 18 15:46:37 2020 +0200
#
# interactive rebase in progress; onto 39357b2
# Last commands done (3 commands done):
#    squash 0e60d12 update README
#    squash 0a5221d fixed typo
# No commands remaining.
# You are currently rebasing branch &#39;tosmi/megafeature&#39; on &#39;39357b2&#39;.
#
# Changes to be committed:
#       modified:   README.md
#</code></pre>
</div>
</div>
<div class="paragraph">
<p>We can see all three commit message and we are going to modify those messages until we are happy</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash"># This is a combination of 3 commits.
# This is the 1st commit message:

updated README.md to megafeature

as we added megafeature, it makes sense to include a short note about it also in README.md

# Please enter the commit message for your changes. Lines starting
# with &#39;#&#39; will be ignored, and an empty message aborts the commit.
#
# Date:      Mon May 18 15:46:37 2020 +0200
#
# interactive rebase in progress; onto 39357b2
# Last commands done (3 commands done):
#    squash 0e60d12 update README
#    squash 0a5221d fixed typo
# No commands remaining.
# You are currently rebasing branch &#39;tosmi/megafeature&#39; on &#39;39357b2&#39;.
#
# Changes to be committed:
#       modified:   README.md
#</code></pre>
</div>
</div>
<div class="paragraph">
<p>When we are happy with new commit message we just save and quit our
editor. Git will now rewirte the history and when we take look at the
commit history again we will see our changes:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">$ git log --oneline
91d1ae2 (HEAD -&gt; tosmi/megafeature) updated README.md to megafeature
39357b2 (origin/tosmi/megafeature) added a mega feature
ddfd077 (upstream/master, master) added rule command
4d8584e (origin/master, origin/HEAD) Update README.md
eb6ccbc Create README.md
60fcabc start using cobra for argument parsing
5140ed0 import .gitignore
d2b55d1 import a simple Makefile
2ecb412 initial import</code></pre>
</div>
</div>
<div class="paragraph">
<p>We only have commit 91d1ae2 now , which includes all three changes from
the commits before.</p>
</div>
<div class="admonitionblock warning">
<table>
<tbody><tr>
<td class="icon">
<i class="fa icon-warning" title="Warning"></i>
</td>
<td class="content">
Rewriting the history of a repository is a dangerous
operation. Especially when you are working in a team. It is not
advised to change the history of commits that got already pushed to a
remote location. Otherwise your teammates will get confused next time
they try to push or pull from the shared repository.
</td>
</tr>
</tbody></table>
</div>
<div class="paragraph">
<p>So it’s OK to change the commit history of a feature branch that only
you are using, but be careful when working on branches more than one
developer is using.</p>
</div>
</div>
</div>]]></content:encoded></item><item><title>Red Hat Satellite Cheat Sheet</title><link>https://blog.stderr.at/integrations/general/2020/04/red-hat-satellite-cheat-sheet/</link><guid isPermaLink="true">https://blog.stderr.at/integrations/general/2020/04/red-hat-satellite-cheat-sheet/</guid><pubDate>Wed, 15 Apr 2020 00:00:00 +0200</pubDate><dc:creator>Articles by Toni Schmidbauer</dc:creator><category>Other</category><description>Cheat sheet for day-to-day Red Hat Satellite administration: useful hammer commands, content views, activation keys and troubleshooting shortcuts for operators.</description><content:encoded><![CDATA[<div class="paragraph">
<p>Cheat sheet for various Red Hat Satellite tasks from a newbie to a newbie.</p>
</div>
<div class="sect1">
<h2 id="_requirements">Requirements</h2>
<div class="sectionbody">
<div class="ulist">
<ul>
<li>
<p>up to Satellite 6.7 RHEL 7.X</p>
</li>
<li>
<p>4 CPU Cores</p>
</li>
<li>
<p>20 GB of RAM</p>
</li>
<li>
<p>300 GB disk space</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>for more info see the <a href="https://access.redhat.com/documentation/en-us/red_hat_satellite/6.6/html/installing_satellite_server_from_a_connected_network/preparing_your_environment_for_installation#storage_requirements">prerequistes guide</a></p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_installation">Installation</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Satellite up to version 6.7 uses puppet for installation. You can use</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">puppet filebucket</code></pre>
</div>
</div>
<div class="paragraph">
<p>to restore files modified by puppet.</p>
</div>
<div class="paragraph">
<p>Satellite requires the <em>Red Hat Satellite Infrastructure Subscription</em>, check if it’s available with</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">subscription-manager list --all --available --matches &#39;Red Hat Satellite Infrastructure Subscription&#39;</code></pre>
</div>
</div>
<div class="paragraph">
<p>If not attach it with</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">subscription-manager attach --pool=pool_id</code></pre>
</div>
</div>
<div class="paragraph">
<p>Next disable all repos and enable only supported repostories via</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">subscription-manager repos --disable &#34;*&#34;</code></pre>
</div>
</div>
<div class="paragraph">
<p>and enable required repositories</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">subscription-manager repos --enable=rhel-7-server-rpms \
--enable=rhel-7-server-satellite-6.6-rpms \
--enable=rhel-7-server-satellite-maintenance-6-rpms \
--enable=rhel-server-rhscl-7-rpms \
--enable=rhel-7-server-ansible-2.8-rpms</code></pre>
</div>
</div>
<div class="paragraph">
<p>then clean cached all repo data via</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash"> yum clean all</code></pre>
</div>
</div>
<div class="paragraph">
<p>and install satellite packages via</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">yum install satellite</code></pre>
</div>
</div>
<div class="paragraph">
<p>Install satellite with</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">satellite-installer --scenario satellite \
--foreman-initial-organization &#34;initial_organization_name&#34; \
--foreman-initial-location &#34;initial_location_name&#34; \
--foreman-initial-admin-username admin_user_name \
--foreman-initial-admin-password admin_password</code></pre>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_backup_restore_cloning">Backup / Restore / Cloning</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Use <code>satellite-maintain</code> for doing offline and online backups</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">satellite-maintain backup offline /backup/</code></pre>
</div>
</div>
<div class="paragraph">
<p>when using the <em>online</em> option make sure that no new content view or
content view versions should be created while the backup is
running. basically satellite should be idle.</p>
</div>
<div class="sect2">
<h3 id="_cloning_satellite">Cloning Satellite</h3>
<div class="paragraph">
<p>The online/offline options also backup <em>/var/lib/pulp</em>, which contains
all downloaded packages. This could be <strong>huge</strong>. There’s an option to skip this so</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">satellite-maintain backup offline --skip-pulp-tar /backup/</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tbody><tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
For a restore you always need the content of <em>/var/lib/pulp</em>.
</td>
</tr>
</tbody></table>
</div>
<div class="paragraph">
<p>This is mainly usefull for cloning satellite. You backup everything
except <em>/var/lib/pulp</em>, copy the backup to a second system and rsync
<em>/var/lib/pulp</em> to the new system. Then restore the backup and
satellite should work as normal on the clone.</p>
</div>
</div>
<div class="sect2">
<h3 id="_snaphot_backups">Snaphot backups</h3>
<div class="paragraph">
<p>Satellite also supports backups via LVM snapshots. For more information see <a href="https://access.redhat.com/documentation/en-us/red_hat_satellite/6.6/html/administering_red_hat_satellite/chap-red_hat_satellite-administering_red_hat_satellite-backup_and_disaster_recovery#snapshot-backup_assembly">Snapshot backup</a></p>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_upgrades">Upgrades</h2>
<div class="sectionbody">
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Read the Satellite release notes</p>
</li>
<li>
<p>Do a offline backup see <a href="#Backup / Restore">[Backup / Restore]</a></p>
</li>
<li>
<p>You could clone satellite to a other system</p>
</li>
<li>
<p>If there are local changes to dhcpd or dns configurations use</p>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">satellite-installer --foreman-proxy-dns-managed=false --foreman-proxy-dhcp-managed=false</code></pre>
</div>
</div>
<div class="paragraph">
<p>to stop satellite-install from overwriting those files.</p>
</div>
</li>
<li>
<p>install the latest version of satellite-maintain via</p>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">yum install rubygem-foreman_maintain</code></pre>
</div>
</div>
</li>
<li>
<p>check for available satellite versions with</p>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">satellite-maintain upgrade list-versions</code></pre>
</div>
</div>
</li>
<li>
<p>test the possible upgrade with</p>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">satellite-maintain upgrade check --target-version 6.7</code></pre>
</div>
</div>
</li>
<li>
<p>and finally run the upgrade and PRAY!</p>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">satellite-maintain upgrade run --target-version 6.7</code></pre>
</div>
</div>
</li>
</ol>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_various_tips_and_tricks">Various tips and tricks</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_installing_packages_via_yum">Installing packages via yum</h3>
<div class="paragraph">
<p>Satellite installs a yum plugin called <code>foreman-protector</code>. If you try
to install a package via yum you get the following message</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">WARNING: Excluding 12190 packages due to foreman-protector.
Use foreman-maintain packages install/update &lt;package&gt;
to safely install packages without restrictions.
Use foreman-maintain upgrade run for full upgrade.</code></pre>
</div>
</div>
<div class="paragraph">
<p>so use</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">satellite-maintain install &lt;package name&gt;</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_os_package_upgrade">OS package upgrade</h3>
<div class="paragraph">
<p>This should be done via satellite-maintain because all packages are locked by default (see <a href="#_installing_packages_via_yum">Installing packages via yum</a>).</p>
</div>
<div class="paragraph">
<p>This basically comes down to running</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-bash hljs" data-lang="bash">oreman-maintain upgrade run --target-version 6.6.z</code></pre>
</div>
</div>
<div class="paragraph">
<p>for upgrading OS packages if you have satellite 6.6 installed.</p>
</div>
</div>
</div>
</div>]]></content:encoded></item></channel></rss>