Simplify Spring Boot Access to Kubernetes Secrets Using Environment Variables

This blog post is a follow-up to a previous blog post titled “Simplify Spring Boot Access to Secrets Using Spring Cloud Kubernetes“. Despite the downsides I mentioned, I already hinted at a more straightforward solution that utilizes environment variables. The plan is to get everything into the Pod with as little configuration effort as possible.

So, I promised a twist, and here it is, thanks to one of my colleagues who pushed me in this direction. Kubernetes gives you yet another tool to handle Secrets in environment variables. This time, it is more convenient since you only point it to the complete Secret, not just a single value. Kubernetes will then make all key-value pairs available as individual environment variables.

Read More »

Simplify Spring Boot Access to Secrets Using Spring Cloud Kubernetes

This topic has its origin in how we manage Kubernetes Secrets at my workplace. We use Helm for deployments, and we must support several environments with their connection strings, passwords, and other settings. As a result, some things are a bit more complicated, and one of them is the access to Kubernetes Secrets from a Spring Boot application running in a Pod.

This blog post covers the following:

  1. How do you generally get Secrets into a Pod?
  2. How do we currently do it using Helm?
  3. How can it be improved with less configuration?
  4. Any gotchas? Of course, it is software.

I will explain a lot of rationales, so expect a substantial amount of prose between the (code) snippets.

Read More »

Apache Commons CLI Handling of –help

An odd thing about Commons CLI is that it has no built-in concept of a “–help” option. Other libraries, like JCommander do (which had other problems, or I would not have bothered with Commons CLI). As a result, you have to build it on your own. It is not enough to include it with all the other application options, especially if you use required arguments. Then it is impossible to only set the Help option.

You must implement a two-step process. See this demo application on GitHub that I created for another blog post. It shows this in action.

First, only parse for the Help option, and if it is present, print the help text and exit the application. To print the complete help text, you must add the other parameters first, though. Otherwise there would be only “–help”.

final var applicationOptions = example_2_Options();

final var options = example_2_Help();
final var cli = parser.parse(options, args, true);

if (cli.hasOption(help)) {
    // Append the actual options for printing to the command-line.
    applicationOptions.getOptions().forEach(options::addOption);
    new HelpFormatter().printHelp("external-config-commons-cli", options);
    return;
}

Second, if no help is requested, parse for the application options.

final var cli = parser.parse(applicationOptions, args, true);

applicationOptions.getOptions().forEach(opt -> {
    if (cli.hasOption(opt)) {
        System.out.printf("Found option %s with value %s%n",
                opt.getOpt(), cli.getOptionValue(opt));
    }
});

Thank you very much for reading. I hope this was helpful.

Spring Boot Externalized Config on Command Line With Apache Commons CLI – Missing Required Option

I know this title is a bit of a mouthful, but you need to get all the keywords in for Google to do its magic 😉. In the previous blog post, I mentioned that I would take another look at this topic through the lens of a programmer that uses Apache Commons CLI for command-line argument handling. In a project for work, I noticed some odd error messages claiming that a command-line option did not have a value assigned to it, although it obviously did.

A more extensive set of examples can be found in the README file on GitHub, together with the code.

The sole reason for this blog post is how unknown parameters from the view of Commons CLI can mess up the parsing. The demo application defines two required Options – one for input (“-i” or “–input”) and one for output (“-o” or “–output”). Consider this command where I also set a Spring configuration setting.

% java -jar target/external-config-commons-cli-1.0.0.jar --spring.config.additional-location=src/config/application-mac.yml -i in -o out
-> AppRunner.run() Command Line Arguments
Argument: --spring.config.additional-location=src/config/application-mac.yml
Argument: -i
Argument: in
Argument: -o
Argument: out
-> ExternalConfigProperties
Input path: /Users/mac/thecode
Output path: /Users/mac/slinger
-> Parsing Help With Apache Commons CLI
-> Parsing Arguments With Apache Commons CLI
Missing required options: i, o

Both options are clearly there. The raw output of the String… args array shows that. By default, Commons CLI complains about unknown options. I disabled that behavior by setting stopAtNonOption to true. The parameter’s name makes no sense to me because it does not stop, but I might misinterpret something.

Either way, I assume that Commons CLI expects an option and a value by default. –spring.config.additional-location=src/config/application-mac.yml is a continuous string, an option without a value – at least to Commons CLI. Then it reads -i as the value to that option, and from there, the parsing goes south. The actual options are interpreted as values now.

Note, though, that Spring still accepts the configuration setting.

How can we fix that? There are two ways to do that:

  1. Add the Spring arguments at the end of the command line.
  2. Use the JVM-style Spring arguments with “-D”, as alluded to in the other blog post.

Putting the argument at the end:

% java -jar target/external-config-commons-cli-1.0.0.jar -i in -o out --spring.config.additional-location=src/config/application-mac.yml
-> AppRunner.run() Command Line Arguments
Argument: -i
Argument: in
Argument: -o
Argument: out
Argument: --spring.config.additional-location=src/config/application-mac.yml
-> ExternalConfigProperties
Input path: /Users/mac/thecode
Output path: /Users/mac/slinger
-> Parsing Help With Apache Commons CLI
-> Parsing Arguments With Apache Commons CLI
Found option i with value in
Found option o with value out

Using the JVM-style:

% java -Dspring.config.additional-location=src/config/application-mac.yml -jar target/external-config-commons-cli-1.0.0.jar -i in -o out
-> AppRunner.run() Command Line Arguments
Argument: -i
Argument: in
Argument: -o
Argument: out
-> ExternalConfigProperties
Input path: /Users/mac/thecode
Output path: /Users/mac/slinger
-> Parsing Help With Apache Commons CLI
-> Parsing Arguments With Apache Commons CLI
Found option i with value in
Found option o with value out

Thank you very much for reading. I hope this was helpful.

Spring Boot Externalized Config on Command Line

Spring Boot applications do not always have to serve as a web service located on the Internet. You can also use Spring Boot (or Spring without the Boot) for a command-line utility. I was recently faced with this task, and one requirement for the tool was to support setting a profile-specific configuration on the command line. This isn’t earth-shattering per se since that is a regular Spring feature. The goal was to provide a profile-specific configuration file on the command line that is not bundled in the application.

Imagine developing a Cloud service and running different environments for the different phases of your project – one for development tests, a staging environment, and, finally, the production environment. Connecting to the different environments may require secrets you do not want to be bundled in the application – and, thus, the source tree.

Now, you could roll your own configuration file reader. But wouldn’t it be nice to make full support of Spring’s @Value annotation or @ConfigurationProperties classes?

Read More »

My Year in Video Gaming 2021

2021 has been a challenging year, for obvious reasons, but also in other personal aspects that are not part of this little essay. Despite all the trials and tribulations, I have probably never played so many games in just one year – some of them in Coop and others all on my lonesome. Many of them I finished, others I, or we, aborted. But not only that, I have also managed to transition from PC gaming to console gaming – a long-held goal of mine.

As always, I am pretty late to the party because I have trouble motivating myself to write stuff, despite having the ideas and mentally developing concepts for them. Much thinking, few doing. One of my 2021 issues.

(I am surprised I managed to get this huge Halo Infinite review out the door.)Here is how this will go. I am starting with a story about why I replaced my gaming PC with consoles and a laptop. Then I transition into my experience with said consoles, and I conclude this gaming year review with the list of games I have played in lonely-mode or Coop. Don’t worry. I didn’t go Halo Infinite on every game. I kept it short-ish because the list is astonishingly long.

Read More »

Halo Infinite Review

When you look back at the history of video-based media, how many games or movies come to your mind with such an iconic theme song that it always evokes a particular feeling whenever you hear it? A theme that you immediately recognize and that conjures specific scenes or gameplay moments you are so fond of? Off the top of my head, I can think of two: The Imperial March from Star Wars and Halo’s invigorating battle soundtrack. Halo is back, infinitely better than Halo 5, and along with it, its recognizable music. I suggest you set the perfect mood and open the link above, and then come back and read my review of Halo Infinite. Start from the beginning because I linked directly to the battle music part (but that is also a good choice).

Now, is it even worth getting in the mood? If you ask yourself, I hope you do not mean my writing 😉. I hope you ask that question because you are anxious for a good game but afraid you might get disappointed. When I read and watched many reviews from known media outlets, I found very different opinions and wasn’t sure what to think. IGN mainly had positive things to say and was very upbeat in their Halo Infinite podcast episode. In contrast, the Germany-based Golem.de website found rather harsh words for some parts, mainly storytelling and the new AI (more on that later). The most common denominator among all of them was the excellent feeling combat. Looking at the complete experience, I think I land somewhere in the middle between Great and Mediocre, and if you are still curious, I will tell you why.

Read More »

Create Native Java Executable using jpackage – Sort of

I have always been the kind of developer who prefers to use native code and write native code. My background is in C++, and I have worked with Microsoft’s WinAPI early in my career. That is to say: I like it fast, and I do not mind going to lower levels.

I am not stuck in the past, though, and as such, I, too, have evolved with the times. I still like C++, but I also see how languages like Java and its great tooling can boost productivity in comparison. As a result, I write code fast. Java is the tool of the trade at my current job, and performance usually is not a problem anymore. The JVM has improved, and computer hardware has, so performance is usually not an issue anymore.

There is one little problem, however: Usage. Let me explain.

Read More »

Apple Silicon M1 for Software Development: Java, C++ with Qt

Apple’s laptops have been making quite the splash since the end of 2020 and have made a massive comeback as a professional tool one year later with the M1 Pro and Max designs. Most of the reviews I have seen focus on the editing and rendering capabilities of these new MacBooks. A few reviewers throw a compile test in the mix, but compiling Chromium or any other huge project is only a part of the equation. Developers don’t just compile code; they also use tools and IDEs to develop their software.

Being new to the M1 world, I wanted to recap my experiences so far briefly. I use Java professionally, and I also have a C++ application based on the Qt framework that I wrote an eon ago and still use productively. Being a former C++ professional, I am about native performance, and I like native software. Therefore, I intended to utilize as many Apple Silicon-native tools as possible. Luckily, one year after its release to the desktop world, the most popular applications have caught up. Let me go through my tool suite one by one.

Read More »

Windows 11 Host VirtualBox Install Error “This app can’t run because it causes security or performance issues”

I have recently upgraded to Windows 11 out of curiosity. Despite the more or less negative first impression, I decided to continue to use it. One of the first applications I install is VirtualBox to try out different Linux flavors and stay current in that world. To my surprise, the VirtualBox installer (version 6.1.26) would not start. Windows was complaining about issues with this software.

> This app can’t run because it causes security or performance issues > on Windows. A new version may be available. Check with your software > provider for an updated version that runs on this version of > Windows.

Well, I checked because it was the latest version of VirtualBox. I found hints on the Internet that VirtualBox does run on Windows 11, albeit without indicating what these persons had done.

A little bit discouraged, I clicked the "Learn more" button. You never know; it might actually be helpful – or a complete waste of time. In this instance, it was of great help. It redirected me to the following Microsoft page discussing the "A driver can’t load on this device issue". It also contains a very convenient link to the corresponding location in the Windows Defender application. Somehow I cannot reproduce that link for your convenience so you must visit Microsoft’s site yourself.

Be aware. There may be a security risk associated with disabling this setting. I have not yet dug deeper to ascertain the whole picture. I figured it must have been disabled or not existed on Windows 10 at all, and I was fine there. Windows will ask you several times to grant administrative rights to perform the operation and require a reboot.

After that, VirtualBox was installed and ran just fine.

Curious, I wondered if I could disable the setting once VirtualBox was installed.

Well, I could not. Windows will try and fail. If you click "Review incompatible drivers", it will show you which component prevents the change. And sure enough, it is VirtualBox.

We will see if Oracle’s VirtualBox team can figure this out, but I would assume so. For now, this works for me.

I hope this has helped you. Thank you for reading.

The Ascent Coop Review Xbox Series X

Do you know the feeling that you occasionally get when watching a gameplay trailer, and you immediately want to get your hands on the game? Like, right now? This sensation does not come around too often for me, and two games managed to do just that last year. One was Outriders and the other one The Ascent, which I am discussing today. I am not sure what exactly did it for me, but probably because it reminded me of something I played in my youth. In 1999, a game named Expendable made the rounds, primarily due to its stunning visuals at the time. Back then, it demonstrated the power of a graphics feature called Environment Mapped Bump Mapping to enamor the game’s textures with depth information and more perceived detail. The core visuals will not excite anyone in 2021, but that game was full of effects and did not hold them back. Expandable still puts on quite a show. 

Games like this are a rare breed and seem to catch my eye whenever one pops up. A more recent example of this type of game that I am aware of is Halo Spartan Assault and Halo Spartan Strike – of which I played the first one. Combine this with stunning visuals in a futuristic, gritty, cyberpunk-themed world, and you get The Ascent. Because it is 2021, no game can make do without some RPG elements. Thus, you get to create your character, level up, and collect loot along the way, making shooting stuff more enjoyable.

And enjoyable it is. Once you get to the point where your brain can cope with the twin-stick-shooting mechanics, and you start to both move and aim in the right direction, The Ascent begins to make a lot of fun – especially in Coop. I discovered how the game works with another player, which is always more motivating than figuring out weird concepts alone. After a while, it started to feel right, and I wanted to continue playing weekend after weekend until we had beaten the game – and that is a good sign.

Here is my report on The Ascent in Coop mode: the good, the bad, and the ugly.

Read More »

Windows 11 First Look at New Visual Design – Not Yet a Fan

Thanks to a recent article by Paul Thurrott, I finally convinced myself to give Windows 11 a try. I was hesitant at first because of all the negative information regarding some of Microsoft’s choices – and I do not mean Secure Boot and TPM. I was not sure if I wanted to support this behavior. Be that as it may, maybe a topic for another day, what finally convinced me was the fact that Secure Boot must not even be enabled. It is enough that the system supports it. This means I can still run a Linux installation in parallel, which I did not want to give up easily.

You must understand that these are really only first impressions. I have not spent hours upon hours with Windows 11 and dug deep into the system. It boils down to an opinion on the visual presentation, the most glaring change compared to Windows 10. Teaser: I do have some mixed feelings about it.

Read More »

Fedora Linux 35 Beta Install NVIDIA Driver (Works on Fedora 36 Too)

This is a quick one because the installation works in the same way as it did in Fedora 34.

First, I added the RPM Fusion repositories as described here.

sudo dnf install \
  https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
sudo dnf install \
  https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm

Next, I installed the akmod-nvidia package like it is explained on this page.

sudo dnf update
sudo dnf install akmod-nvidia

One reboot later, the NVIDIA module was up and running.

$ lsmod | grep nvidia
nvidia_drm             69632  4
nvidia_modeset       1200128  8 nvidia_drm
nvidia              35332096  408 nvidia_modeset
drm_kms_helper        303104  1 nvidia_drm
drm                   630784  8 drm_kms_helper,nvidia,nvidia_drm

For completeness: my computer has an NVIDIA GT1030.

I hope this helped you, and thank you for reading.

C# Delegate, Action, Func, Predicate Explained

Depending on your entry point to delegates, the documentation might look a tad confusing at first. For me, it was The delegate type section of the C# language reference. It throws around terms like Action, Func, Events, custom delegate types. Predicate is also related to this topic, and this was what I was looking for.

Let me briefly explain what all those words mean and how they relate to delegate. Then I will explain why I was looking into this.

Short teaser: “Named Predicate”, like a Hibernate Named Query.

Read More »

Emulate Java Enums With Values in C# (Pt. 2, Improved With Conversion Operator Overload)

In a previous blog post, I demonstrated how Java’ enums that contain one or more values/objects can be emulated with C#. One thing bothered me, though: the switch statement and how inconvenient it was to determine the proper type. Worst of all, it was not type-safe. In my simple example, it was easy because I was using strings. Imagine your fake-enum does not contain a string to quickly identify the instance.

Well, there is a prettier workaround – and it involves an actual enum. I was thinking about how the same could be done in C++ and in C++, you can have type conversion operators. Then I searched if such a feature also exists in C#, and sure enough, it does.

Read More »