Terraform eks module - workers custom tags - kubernetes

I want to have 2 worker groups, each with custom tag.
For example, if I use this template - https://github.com/terraform-aws-modules/terraform-aws-eks/blob/v4.0.2/examples/basic/main.tf
worker_groups = [
{
name = "worker-group-1"
....
//here - what I want to have
tags = {selector=wg1}
},
{
name = "worker-group-2"
....
//here - what I want to have
tags = {selector=wg2}
},
I see the input variables in https://github.com/terraform-aws-modules/terraform-aws-eks/blob/v4.0.2/variables.tf , lines 115-122
and template - https://github.com/terraform-aws-modules/terraform-aws-eks/blob/v4.0.2/workers.tf , lines 19-29,
but I can't understand how to properly configure them to get custom tags on workers.

The current version has changed slightly:
worker_groups = [
{
name = "worker-group-1"
....
tags = [
{
key = "k1"
value = "v1"
propagate_at_launch = true
},
{
key = "k2"
value = "v2"
propagate_at_launch = true
}
]
}]

I've found where it was implemented and the example how to use it:
worker_groups = [
{
name = "worker-group-1"
....
},
{
name = "worker-group-2"
....
},
]
// and here comes the tags block
worker_group_tags = {
worker-group-1 = [
{
key = "k1"
value = "v1"
key = "k2"
value = "v2"
propagate_at_launch = true
},
],
worker-group-2 = [
{
key = "k3"
value = "v3"
key = "k4"
value = "v4"
propagate_at_launch = true
},
],
}

Related

What is the proper way to register policy-enforcer configuration in ktor

In spring boot, adding keycloak adaptor and "keycloak.policy-enforcer-config.claimInformationPointConfig.claims[claim-from-uri]={ request.uri }" to application.properties
file, I am able to receive "claim-from-uri" in keycloak javascript policy. But using similar settings in ktor does not work.
I have added "policy-enforcer" to keyclaok.json but "claim-from-uri" property is always null in javascript policy in keycloak.
// js policy in keycloak
var context = $evaluation.getContext();
var attributes = context.getAttributes();
var realm = $evaluation.getRealm();
var httpUri = attributes.getValue('http.uri');
var claimFromUri = attributes.getValue('claim-from-uri');
My usecase is to get the claim from the URI and then use it to get the policy from the keycloak server.
Below is my keycloak.json file.
{
"realm": "test-realm",
"auth-server-url": "https://localhost:8080/auth",
"ssl-required": "none",
"resource": "api-resource",
"public-client": true,
"policy-enforcer": {
"enforcement-mode": "ENFORCING",
"paths": [
{
"path": "/api/*",
"claim-information-point": {
"claims": {
"claim-from-uri": "{request.uri}"
}
},
"methods": [
{
"method": "GET",
"scopes": ["get", "GET"]
},
{
"method": "POST",
"scopes": ["post", "POST"]
}
]
}
]
}
}
val keycloakProvider = OAuthServerSettings.OAuth2ServerSettings(
name = "keycloak",
authorizeUrl = "https://localhost:8082/auth/realms/test-realm/protocol/openid-connect/auth",
accessTokenUrl = "https://localhost:8082/auth/realms/test-realm/protocol/openid-connect/token",
clientId = "test-realm-backend",
clientSecret = "client-secret",
accessTokenRequiresBasicAuth = false,
requestMethod = HttpMethod.Post,
)
//application setup
install(Authentication) {
oauth("keycloak") {
client = HttpClient(Apache)
providerLookup = { keycloakProvider }
urlProvider = { "http://localhost:8080/callback" }
}
}
// routing
authenticate("keycloak") {
get("/api/{name}") {
val principal: OAuthAccessTokenResponse.OAuth2? = call.authentication.principal()
call.sessions.set(UserSession("Bearer $principal?.accessToken.toString()"))
val name = call.parameters["name"] ?: "name missing in parameter"
val user = User(name)
call.respond(user)
}
}

Creating multiple namespaces using Terraform

I am trying to create multiple namespaces from a json blob input file like below:
my tfvars.json file
{
"example1" : [
{
"namespace_name" : "test-1",
"team_name" : "test",
},
{
"namespace_name" : "test-2",
"team_name" : "test2",
}
]
}
My main.tf file looks as below:
resource "kubernetes_namespace" "aks_namespace" {
metadata {
annotations = {
name = var.namespace_name
}
labels = {
name = var.team_name
}
name = var.namespace_name
}
}
I have tried almost all the options available like for_each and dynamic.. nothing seems to be working to create the namespaces in loop.
Just wondering if this is really possible..
Unfortunately, I am not supposed to change the input .json format..
Any suggestions or ideas?
I tried with all possibilities using your details but as the example1 is a tuple value , declaring it in for_each will error out creating namespace.
So , as a solution I declared variable example1 in terraform.tfvars.json as below:
{ "example1" : [
[
"test-1",
"test"
],
[
"test-2",
"test2"
]
]
}
This is the main.tf I am using:
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.5.0"
}
}
}
variable "example1" {
}
provider "kubernetes" {
# Configuration options
}
resource "kubernetes_namespace" "aks_namespace" {
for_each = {for i,v in var.example1: i=>v}
metadata {
annotations = {
name = each.value[0]
}
labels = {
name = each.value[1]
}
name = each.value[0]
}
}
Outputs:
Update:
terraform.tfvars.json
{
"example1" : [
{
"namespace_name" : "test-1",
"team_name" : "test"
},
{
"namespace_name" : "test-2",
"team_name" : "test2"
}
]
}
main.tf
terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = "2.5.0"
}
}
}
variable "example1" {
type = list(object({
namespace_name = string
team_name = string
}))
}
provider "kubernetes" {
# Configuration options
}
resource "kubernetes_namespace" "aks_namespace" {
for_each = {for i,v in var.example1: i=>v}
metadata {
annotations = {
name = var.example1[each.key].namespace_name
}
labels = {
name = var.example1[each.key].team_name
}
name = var.example1[each.key].namespace_name
}
}

reading Play application configuration file containing nested objects

I want to get list of email IDs based on provided fileType and companyName
def getEmailAddresses(fileType: String, companyName: String): List[String] = {
val xz = Play.application.configuration.getConfigList("email_list")
println(xz)
}
my above function is giving me some complex List of Configuration which is not easily traversable.
I basically want List[String] which is nothing but list of email IDs.
For example, given arguments :
fileType = test_2
companyName = company2
I want to obtain String "user1#gmail.com, user2#gmail.com"
that can be converted to List[String] by .split(",").toList
can this be simplified?
following is my application.conf file in scala play application
email_list = [
{
file0 : "user1#gmail.com,user2#gmail.com"
},
{
file1 : [
{"company1" : "user1#gmail.com"},
{"company2" : "user1#gmail.com"},
{"company3" : "user1#gmail.com"}
]
},
{
top2 = [
{"company1": "user1#gmail.com,user2#gmail.com"},
{"company2": "user1#gmail.com,user2#gmail.com"},
{"company3": "user1#gmail.com,user2#gmail.com"}
]
},
{
test_2 = [
{"company1": "user1#gmail.com,user2#gmail.com"},
{"company2": "user1#gmail.com,user2#gmail.com"},
{"company3": "user1#gmail.com,user2#gmail.com"}
]
},
{
xyz_7 = [
{"company1": "user1#gmail.com,user2#gmail.com"},
{"company2": "user1#gmail.com,user2#gmail.com"},
{"company3": "user1#gmail.com,user2#gmail.com"}
]
},
{
abc_def = [
{"company1": "user1#gmail.com,user2#gmail.com"},
{"company2": "user1#gmail.com,user2#gmail.com"},
{"company3": "user1#gmail.com,user2#gmail.com"}
]
}
]
I have done some trials on HOCON Syntax and found following code + config to be working
code
def getEmailAddresses(fileType: String, companyName: String): List[String] = {
// fileType = "file1"
// companyName = "company1"
val file0 = Play.application.configuration.getString("email_list.file0")
println(file0)
val file1_company1 = Play.application.configuration.getString(s"email_list.${fileType}.${companyName}")
println(file1_company1)
}
application conf
email_list {
file0 = "user1#gmail.com,user2#gmail.com"
file1 {
company1 = "user1#gmail.com"
company2 = "user1#gmail.com"
company3 = "user1#gmail.com"
}
top2 {
company1 = "user1#gmail.com,user2#gmail.com"
company2 = "user1#gmail.com,user2#gmail.com"
company3 = "user1#gmail.com,user2#gmail.com"
}
test_2 {
company1 = "user1#gmail.com,user2#gmail.com"
company2 = "user1#gmail.com,user2#gmail.com"
company3 = "user1#gmail.com,user2#gmail.com"
}
xyz_7 {
company1 = "user1#gmail.com,user2#gmail.com"
company2 = "user1#gmail.com,user2#gmail.com"
company3 = "user1#gmail.com,user2#gmail.com"
}
abc_def {
company1 = "user1#gmail.com,user2#gmail.com"
company2 = "user1#gmail.com,user2#gmail.com"
company3 = "user1#gmail.com,user2#gmail.com"
}
}

Custom control Openui5

sap.ui.core.Element.extend("custom.barNlineChartControl", { metadata : {
properties : {
"Job" : {type : "string", group : "Misc", defaultValue : null},
"Threshold" : {type : "int", group : "Misc", defaultValue : null},
}
}});
sap.ui.core.Control.extend("control.barNlinechart", {
/* the control API */
metadata : {
aggregations : {
"items" : { type: "custom.barNlineChartControl", multiple : true, singularName : "item"}
},
events: {
"select" : {},
"selectEnd": {}
}
},
//D3 Code below:
onAfterRendering: function() {
var that = this;
/* get the Items aggregation of the control and put the data into an array */
var aItems = this.getItems();
var data = [];
for (var i=0;i<aItems.length;i++){
var oEntry = {};
for (var j in aItems[i].mProperties) {
oEntry[j]=aItems[i].mProperties[j];
}
data.push(oEntry);
}
alert(JSON.stringify(data));
Code of view & control
multiBarLineGraph = new control.barNlinechart({
layoutData: new sap.ui.layout.GridData({span: "L12 M12 S12"}),
items: {
path : "/genericData",
template : new custom.barNlineChartControl({Job:"{Job}",Threshold:"{Threshold}"}),
}
}),
var multiBarData = {
"genericData":[
{
"Job": "Doctor",
"Threshold": 45,
"Hospital1": 30,
"Hospital2": 100,
"Hospital3": 90,
},
{
"Job": "Teacher",
"Threshold": 65,
"School1": 60,
"School2": 75,
},
]};
When the alert in d3 code executes I get Job & Threshold but other data from JSON array are missing which is obvious as the properties set here only accept job and threshold. As the JSON is dynamic how to write custom control so that I can pass the complete data to control everytime no matter how dynamic the data be.
You could use type: "any" for your items and dont use the element custom.barNlineChartControl at all:
Edit: as an aggregation controls the lifetime of the aggregated objects you have to use a property in this case.
sap.ui.core.Control.extend("control.barNlinechart", {
/* the control API */
metadata : {
properties : {
"items" : { type: "any" }
},
events: {
"select" : {},
"selectEnd": {}
}
},
and then in your view:
multiBarLineGraph = new control.barNlinechart({
layoutData: new sap.ui.layout.GridData({span: "L12 M12 S12"}),
items: { path : "/genericData" }
}),
this.getItems() would return an array of whatever has been been set / bound.

jstree initially_select and initially_open

The below lines of code while using jstree, throws an exception mentioned in the link
http://code.google.com/p/jstree/issues/detail?id=294
**"ui" : { "initially_select" : [ quotedAndCommaSeparated ] }**
**"core" : { "animation" : 0, "initially_open" : [ quotedAndCommaSeparated ] }**
If i use hard coded values like below, it works without any issues.
"ui" : { "initially_select" : ['3381','7472','7473','7474','7247','7248','7249','3273','3272'] }
"core" : { "animation" : 0, "initially_open" : [ '3381','7472','7473','7474','7247','7248','7249','3273','3272' ] }
I have formed the quotedAndCommaSeparated from an array and it is the same as the hard coded values above. But still the issue is not resolved. Please suggest.
quotedAndCommaSeparated = '3381','7472','7473','7474','7247','7248','7249','3273','3272'
Complete code for ur reference:
For Scripts:
static.jstree.com/v.1.0pre/jquery.jstree.js
static.jstree.com/v.1.0pre/_docs/syntax/!script.js
function BindTreeView(nodeToHighlight, isInitialLoad)
{
var initiallySelect = [];
var searchOption = 0;
if($('#rbobtnSelectedLevelAndBelowRadio:checked').val() == 'Selected Level and Below')
searchOption = 1;
else if($('#rdobtnCurrentOrganization:checked').val() == 'Current Organization')
searchOption = 2;
if(searchOption == 0)
initiallySelect.push(nodeToHighlight);
else if (searchOption == 1 || searchOption == 2)
{
var grid = $("#SearchResultJQGrid");
ids = grid.jqGrid("getDataIDs");
if(ids && ids.length > 0)
{
for(var iRow = 1; iRow < ids.length; iRow++)
{
var dataRow = $("#SearchResultJQGrid").getRowData(iRow);
var companyId = dataRow.CompanyID;
initiallySelect.push(companyId);
}
}
}
var quotedAndCommaSeparated = "'" + initiallySelect.join("','") + "'";
var urlRef = '/Group/GetDataForTreeView';
$('#TreeView').jstree({
"json_data" : {
"ajax" : {
"cache": false,
"url": function (node) {
var nodeId = "";
if (node == -1)
url = urlRef;
return url;
},
"data" : function (n) {
return { id : n.attr ? n.attr("id") : 0 };
}
}
},
"ui" : { "initially_select" : [ quotedAndCommaSeparated ] },
"core" : { "animation" : 0, "initially_open" : [ quotedAndCommaSeparated ] },
"themes": {
"theme": "classic",
"dots": true,
"icons": false
},
"plugins" : [ "themes", "json_data", "ui", "core" ]
}).bind("select_node.jstree", function (event, data) { if(isInitialLoad == true)
isInitialLoad = false;
else
BindGridView('CV', data.rslt.obj.attr("name"), data.rslt.obj.attr("id"), isInitialLoad);
});
}
Your bug is that quotedAndCommaSeparated is not a list, it's just a string.
You should simply add strings instead of numbers to the initiallySelect list
initiallySelect.push(companyId + "");
Then you can use this directly in the jstree init
"ui" : { "initially_select" : [ initiallySelect ] },
Hope that helps.