---
policy: /ce/ca/google/gke/node-pool-auto-repair
logic: /ce/ca/google/gke/node-pool-auto-repair/prod.logic.yaml
executionTime: 2025-10-25T12:02:45.878900213Z
generationMs: 62
executionMs: 721
rows:
  - id: '001'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10G1__nodeManagementAutoRepair__c') != 'Enabled'
      actual: extract('CA10G1__nodeManagementAutoRepair__c') != 'Enabled'
    runtimeError: {}
  - id: '002'
    match: true
    status:
      expected: COMPLIANT
      actual: COMPLIANT
    conditionIndex:
      expected: 200
      actual: 200
    conditionText:
      expected: otherwise
      actual: otherwise
    runtimeError: {}
  - id: '003'
    match: true
    status:
      expected: INCOMPLIANT
      actual: INCOMPLIANT
    conditionIndex:
      expected: 199
      actual: 199
    conditionText:
      expected: extract('CA10G1__nodeManagementAutoRepair__c') != 'Enabled'
      actual: extract('CA10G1__nodeManagementAutoRepair__c') != 'Enabled'
    runtimeError: {}
usedFiles:
  - path: /ce/ca/google/gke/node-pool-auto-repair/policy.yaml
    md5Hash: 9271055661618B3210B5DA9F88B2A833
    content: "---\nnames: \n  full: \"Google GKE Cluster Node Pool Auto-Repair is\
      \ disabled\"\n  contextual: \"Cluster Node Pool Auto-Repair is disabled\"\n\
      description: \"Ensures that GKE Cluster Node Pools have the Auto-Repair feature\\\
      \n  \\ enabled. This feature helps maintain node health by automatically repairing\\\
      \n  \\ nodes that fail health checks.\"\ntype: \"COMPLIANCE_POLICY\"\ncategories:\n\
      \  - \"RELIABILITY\"\nframeworkMappings:\n  - \"/frameworks/cis-gke-v1.8.0/05/05/02\"\
      \n  - \"/frameworks/pci-dss-v3.2.1/02/02\"\n  - \"/frameworks/cloudaware/resource-reliability/system-configuration\"\
      \n"
  - path: /ce/ca/google/gke/node-pool-auto-repair/prod.logic.yaml
    md5Hash: 0F6FA7D30621E0944C1630D0CC125F4D
    content: |
      ---

      inputType: "CA10G1__CaGoogleGkeClusterNodePool__c"
      testData:
        - file: "test-data.json"
      importExtracts:
        - file: "/types/CA10G1__CaGoogleGkeClusterNodePool__c/object.extracts.yaml"
      conditions:
        - status: "INCOMPLIANT"
          currentStateMessage: "Node Pool auto repair feature is disabled."
          remediationMessage: "Enable auto repair feature for the Cluster."
          check:
            NOT_EQUAL:
              left:
                EXTRACT: "CA10G1__nodeManagementAutoRepair__c"
              right:
                TEXT: "Enabled"
      otherwise:
        status: "COMPLIANT"
        currentStateMessage: "Cluster's auto repair feature is enabled."
  - path: /ce/ca/google/gke/node-pool-auto-repair/test-data.json
    md5Hash: 5FA3C9495580ADEE41DCB0058C7CAEC9
    content: |
      [
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "199",
            "conditionText": "extract('CA10G1__nodeManagementAutoRepair__c') != 'Enabled'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-08T10:28:58Z" },
          "Id": "001",
          "CA10G1__disappearanceTime__c": null,
          "CA10G1__nodeManagementAutoRepair__c": "Disabled"
        },
        {
          "expectedResult": {
            "status": "COMPLIANT",
            "conditionIndex": "200",
            "conditionText": "otherwise",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-08T10:28:58Z" },
          "Id": "002",
          "CA10G1__disappearanceTime__c": null,
          "CA10G1__nodeManagementAutoRepair__c": "Enabled"
        },
        {
          "expectedResult": {
            "status": "INCOMPLIANT",
            "conditionIndex": "199",
            "conditionText": "extract('CA10G1__nodeManagementAutoRepair__c') != 'Enabled'",
            "runtimeError": null
          },
          "context": { "snapshotTime": "2025-09-08T10:28:58Z" },
          "Id": "003",
          "CA10G1__disappearanceTime__c": null,
          "CA10G1__nodeManagementAutoRepair__c": null
        }
      ]
  - path: /types/CA10G1__CaGoogleGkeClusterNodePool__c/object.extracts.yaml
    md5Hash: 0A652ABADAA95854B5E133EB8B5BBD45
    content: "---\nextracts:\n  - name: \"CA10G1__nodeManagementAutoRepair__c\"\n\
      \    value: \n      FIELD:\n        path: \"CA10G1__nodeManagementAutoRepair__c\"\
      \n  - name: \"CA10G1__nodeManagementAutoUpgrade__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10G1__nodeManagementAutoUpgrade__c\"\n  - name: \"CA10G1__nodeConfigImageType__c\"\
      \n    value: \n      FIELD:\n        path: \"CA10G1__nodeConfigImageType__c\"\
      \n  - name: \"CA10G1__nodeConfigServiceAccount__c\"\n    value: \n      FIELD:\n\
      \        path: \"CA10G1__nodeConfigServiceAccount__c\"\n"
script: |-
  CREATE TEMP FUNCTION mock_ExpectedResult()
  RETURNS ARRAY<STRUCT<
          Id STRING,
          expectedResult STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, runtimeError STRING>
      >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "Id" : "001",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10G1__nodeManagementAutoRepair__c') != 'Enabled'",
      "runtimeError" : null
    }
  }, {
    "Id" : "002",
    "expectedResult" : {
      "status" : "COMPLIANT",
      "conditionIndex" : "200",
      "conditionText" : "otherwise",
      "runtimeError" : null
    }
  }, {
    "Id" : "003",
    "expectedResult" : {
      "status" : "INCOMPLIANT",
      "conditionIndex" : "199",
      "conditionText" : "extract('CA10G1__nodeManagementAutoRepair__c') != 'Enabled'",
      "runtimeError" : null
    }
  } ];
  """;

  CREATE TEMP FUNCTION mock_CA10G1__CaGoogleGkeClusterNodePool__c()
  RETURNS ARRAY<STRUCT<
      CA10G1__disappearanceTime__c TIMESTAMP,
      CA10G1__nodeManagementAutoRepair__c STRING,
      Id STRING,
      context STRUCT<
          snapshotTime TIMESTAMP
      >
  >>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
    return [ {
    "context" : {
      "snapshotTime" : new Date("2025-09-08T10:28:58Z")
    },
    "CA10G1__nodeManagementAutoRepair__c" : "Disabled",
    "Id" : "001"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-08T10:28:58Z")
    },
    "CA10G1__nodeManagementAutoRepair__c" : "Enabled",
    "Id" : "002"
  }, {
    "context" : {
      "snapshotTime" : new Date("2025-09-08T10:28:58Z")
    },
    "CA10G1__nodeManagementAutoRepair__c" : null,
    "Id" : "003"
  } ];
  """;

  CREATE TEMP FUNCTION process_CA10G1__CaGoogleGkeClusterNodePool__c(
      obj STRUCT<
          CA10G1__disappearanceTime__c TIMESTAMP,
          CA10G1__nodeManagementAutoRepair__c STRING,
          Id STRING
      >,
      snapshotTime TIMESTAMP
  )
  RETURNS STRUCT<status STRING, conditionIndex DECIMAL, conditionText STRING, currentStateMessage STRING, currentStateReferences STRING, remediation STRING, runtimeError STRING>
  DETERMINISTIC
  LANGUAGE js
  AS r"""
  var TextLib = new function () {
      this.normalize = function(arg) {
          return arg == null ? '' : arg.replace(/\s+/g, ' ').trim().toLowerCase();
      };
      this.isEmpty = function(arg) {
          return this.normalize(arg) == '';
      };
      this.isNotEmpty = function(arg) {
          return this.normalize(arg) != '';
      };
      this.equal = function(left, right) {
          return this.normalize(left) == this.normalize(right);
      };
      this.notEqual = function(left, right) {
          return this.normalize(left) != this.normalize(right);
      };
      this.startsWith = function(arg, substring) {
          return this.normalize(arg).startsWith(this.normalize(substring));
      };
      this.endsWith = function(arg, substring) {
          return this.normalize(arg).endsWith(this.normalize(substring));
      };
      this.contains = function(arg, substring) {
          return this.normalize(arg).includes(this.normalize(substring));
      };
      this.containsAll = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.every(sub => normalizedArg.includes(this.normalize(sub)));
      };
      this.containsAny = function(arg, substrings) {
          if (substrings == null || substrings.length === 0) return false;
          let normalizedArg = this.normalize(arg);
          return substrings.some(sub => normalizedArg.includes(this.normalize(sub)));
      };
  }();
      var references1 = [];
      // condition[0], conditionIndex:[0..99]
      references1.push('Deleted From Google [CA10G1__disappearanceTime__c]: ' + obj.CA10G1__disappearanceTime__c);
      if (obj.CA10G1__disappearanceTime__c != null) {
          return {status: 'DISAPPEARED', conditionIndex: 99, conditionText: "isDisappeared(CA10G1__disappearanceTime__c)", currentStateMessage: "Object is deleted in the source", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
      }
      // condition[1], conditionIndex:[100..199]
      function extract3() { if (!this.out) { this.out = obj.CA10G1__nodeManagementAutoRepair__c; } return this.out; };
      references1.push('Node Management: Auto-Repair [obj.CA10G1__nodeManagementAutoRepair__c]: ' + obj.CA10G1__nodeManagementAutoRepair__c);
      if (TextLib.notEqual(extract3.call(extract3), 'Enabled')) {
          return {status: 'INCOMPLIANT', conditionIndex: 199, conditionText: "extract('CA10G1__nodeManagementAutoRepair__c') != 'Enabled'", currentStateMessage: "Node Pool auto repair feature is disabled.", currentStateReferences: references1.join('\n'), remediation: "Enable auto repair feature for the Cluster.", runtimeError: null};
      }
      return {status: 'COMPLIANT', conditionIndex: 200, conditionText: "otherwise", currentStateMessage: "Cluster's auto repair feature is enabled.", currentStateReferences: references1.join('\n'), remediation: null, runtimeError: null};
  """;


  SELECT
    expectedResult.Id as Id,
    IF (
      IFNULL(expectedResult.expectedResult.status, '') = IFNULL(sObject.result.status, '')
      AND IFNULL(expectedResult.expectedResult.conditionIndex, -1) = IFNULL(sObject.result.conditionIndex, -1)
      AND IFNULL(expectedResult.expectedResult.conditionText, '') = IFNULL(sObject.result.conditionText, '')
      AND IFNULL(expectedResult.expectedResult.runtimeError, '') = IFNULL(sObject.result.runtimeError, ''),
      "MATCH",
      "FAIL"
    ) as match,
    expectedResult.expectedResult.status as expectedStatus, sObject.result.status as actualStatus,
    expectedResult.expectedResult.conditionIndex as expectedConditionIndex, sObject.result.conditionIndex as actualConditionIndex,
    expectedResult.expectedResult.conditionText as expectedConditionText, sObject.result.conditionText as actualConditionText,
    expectedResult.expectedResult.runtimeError as expectedRuntimeError, sObject.result.runtimeError as actualRuntimeError
  FROM UNNEST(mock_ExpectedResult()) expectedResult
  LEFT JOIN (
      SELECT
          sObject.CA10G1__disappearanceTime__c AS CA10G1__disappearanceTime__c,
          sObject.CA10G1__nodeManagementAutoRepair__c AS CA10G1__nodeManagementAutoRepair__c,
          sObject.Id AS Id,
          process_CA10G1__CaGoogleGkeClusterNodePool__c(
              STRUCT(
                  sObject.CA10G1__disappearanceTime__c AS CA10G1__disappearanceTime__c,
                  sObject.CA10G1__nodeManagementAutoRepair__c AS CA10G1__nodeManagementAutoRepair__c,
                  sObject.Id AS Id
              ),
              sObject.context.snapshotTime
          ) as result
      FROM UNNEST(mock_CA10G1__CaGoogleGkeClusterNodePool__c()) AS sObject
  ) sObject ON sObject.Id = expectedResult.Id;
