Skip to content

Instantly share code, notes, and snippets.

@joshbeard
Created January 23, 2024 16:11
Show Gist options
  • Save joshbeard/46fe63df1cee4c64edaf7ab0e4ec8d43 to your computer and use it in GitHub Desktop.
Save joshbeard/46fe63df1cee4c64edaf7ab0e4ec8d43 to your computer and use it in GitHub Desktop.
EKS Kubernetes version with Renovate

eks-k8s-version-scraper.js

// Script to scrape the EKS Kubernetes versions from the AWS documentation
// and produce a JSON file that Renovate can parse.
// Usage: node eks-k8s-version-scraper.js > eks-k8s-versions.json
const axios = require('axios');
const cheerio = require('cheerio');
const fs = require('fs');

const url = 'https://docs.aws.amazon.com/eks/latest/userguide/kubernetes-versions-standard.html';

axios.get(url)
  .then(response => {
    const html = response.data;
    const $ = cheerio.load(html);
    const releases = [];

    $('h2').each((i, elem) => {
      const id = $(elem).attr('id');
      if (id && id.startsWith('kubernetes-')) {
        const version = id.split('-')[1];
        const changelogUrl = `https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-${version}.md`;
        releases.push({ version, changelogUrl });
      }
    });

    const result = {
      releases,
      changelogUrl: "https://docs.aws.amazon.com/eks/latest/userguide/kubernetes-versions-standard.html",
      homepage: "https://docs.aws.amazon.com/eks/latest/userguide/kubernetes-versions-standard.html"
    };

    console.log(JSON.stringify(result, null, 2));
  })
  .catch(error => {
    console.error('Error fetching the HTML document:', error);
  });

renovate.json

{
    "$schema": "https://docs.renovatebot.com/renovate-schema.json",
    "extends": [
        "config:base"
    ],
    "customDatasources": {
        "eks": {
            "defaultRegistryUrlTemplate": "file://eks-k8s.json",
            "transformTemplates": []
        }
    },
    "customManagers": [
        {
            "customType": "regex",
            "datasourceTemplate": "custom.eks",
            "fileMatch": ["example-eks-terraform/main.tf"],
            "matchStrings": [
                "eks_version\\s*=\\s*\"(?<currentValue>\\d+\\.\\d+)\""
            ],
            "depNameTemplate": "eks"
        }
    ],
    "packageRules": [
        {
            "matchDatasources": [
                "custom.eks"
            ],
            "extractVersion": "(?<version>.+)$"
        }
    ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment